task-b complate

This commit is contained in:
phaichayon
2026-06-11 16:55:45 +07:00
parent 7a390cf0df
commit 67545d9295
135 changed files with 3295 additions and 6385 deletions

View File

@@ -1,337 +0,0 @@
# ALLA-ITCENTER Roadmap
Version: 1.0
Status: Planning
---
# Vision
ALLA-ITCENTER เป็นแพลตฟอร์มบริหารจัดการงาน IT Operations สำหรับองค์กร
ครอบคลุม
* IT Asset Management
* Software Asset Management
* Lifecycle Management
* Inventory Management
* IT Service Management
* IT Governance
---
# Architecture Principles
อ้างอิงจาก AGENTS.md และ Dashboard Skill
## Technical Direction
* Next.js App Router
* Route Handlers
* PostgreSQL
* Drizzle ORM
* TanStack Query
* TanStack Form
* Feature Based Architecture
* Organization Aware RBAC
---
# Phase 0 - Foundation
Goal
สร้างข้อมูลกลางขององค์กร
## Modules
### Company Management
```text
src/features/company
```
### Site Management
```text
src/features/site
```
### Department Management
```text
src/features/department
```
### Location Management
```text
src/features/location
```
### Employee Management
```text
src/features/employee
```
### Vendor Management
```text
src/features/vendor
```
### Attachment Management
```text
src/features/attachment
```
---
Deliverables
* Company
* Site
* Building
* Floor
* Area
* Department
* Employee
* Vendor
---
# Phase 1 - Asset Core (MVP)
Goal
สร้าง Single Source of Truth ของ Asset
แก้ปัญหา
* ไม่รู้ใครถือครอง
* หาของไม่เจอ
* ตรวจนับไม่ตรง
* Asset History สูญหาย
## Modules
### Asset Management
```text
src/features/assets
```
### Asset Assignment
```text
src/features/asset-assignments
```
### Asset Transfer
```text
src/features/asset-transfers
```
### Asset Movement
```text
src/features/asset-movements
```
### Asset Dashboard
```text
src/features/asset-dashboard
```
---
Deliverables
* Asset Master
* Assignment
* Transfer
* Return
* Movement Timeline
* Dashboard
---
# Phase 2 - Governance & Lifecycle
Goal
บริหารความเสี่ยงของ Asset
## Modules
### Warranty
```text
src/features/warranties
```
### Contracts
```text
src/features/contracts
```
### Lifecycle
```text
src/features/lifecycle
```
### Asset Audit
```text
src/features/asset-audits
```
### Risk Dashboard
```text
src/features/risk-dashboard
```
---
Deliverables
* Warranty Tracking
* EOS
* EOL
* EOP
* Audit
* Risk Dashboard
---
# Phase 3 - Inventory & Stock
Goal
ควบคุมอุปกรณ์คงคลัง
## Modules
### Stockroom
### Stock Transactions
### Consumables
### Spare Parts
---
Deliverables
* Stock Control
* Spare Part Tracking
* Consumable Tracking
---
# Phase 4 - Software Asset Management
Goal
ควบคุม Software และ License
## Modules
### Software Catalog
### License Management
### Subscription Management
### SaaS Management
### License Assignment
---
Deliverables
* License Tracking
* SaaS Tracking
* License Utilization
---
# Phase 5 - IT Service Management
Goal
จัดการงานบริการ IT
## Modules
### Incident
### Service Request
### Problem
### Change
### Knowledge Base
---
Deliverables
* Helpdesk
* Service Portal
* Change Management
---
# Phase 6 - IT Governance Platform
Goal
ยกระดับเป็น IT Operations Platform
## Modules
### Procurement Tracking
### Budget Planning
### Refresh Planning
### Vendor Evaluation
### Capacity Planning
### Executive Dashboard
---
Deliverables
* Asset Forecast
* Budget Forecast
* Lifecycle Forecast
* Governance Dashboard
---
# Success Criteria
Platform สามารถตอบได้ว่า
* ใครถือครอง Asset
* Asset อยู่ที่ไหน
* Asset มีความเสี่ยงหรือไม่
* Asset จะหมดอายุเมื่อใด
* Asset เคยผ่านเหตุการณ์ใดบ้าง
* IT ใช้งบประมาณเท่าไรในอนาคต

View File

@@ -1,200 +0,0 @@
# IT Asset Governance MVP Plan For This Dashboard Repo
## Summary
Implement the IT Center MVP as a new app-owned feature set inside the existing Next.js dashboard, using the current architecture:
- `organizations` stays the tenant boundary and maps to `Company`
- business roles (`IT Admin`, `Helpdesk`, `Infrastructure`, `Application`, `Auditor`, `Viewer`) are modeled as workspace-scoped permission bundles, not as replacements for `systemRole`
- first release is a `Core Registry` MVP:
- master data
- asset register
- asset lifecycle transactions: assign, transfer, return, repair
- movement history
- basic dashboard summaries and risk widgets
This should be built as a new feature family, following the migrated `products` and `users` patterns:
`feature types -> service -> queries/mutations -> route handlers -> Drizzle`.
## Key Changes
### 1. Domain model and tenancy alignment
- Treat `organization` as `Company`; keep the existing table and session/org-switcher model.
- Add company-scoped master data tables under the selected organization:
- `sites`
- `departments`
- `locations`
- `employees`
- Add asset domain tables:
- `assets`
- `asset_movements`
- `asset_repairs`
- Keep `Asset UID` immutable and system-generated.
- Keep `Asset Code` mutable and history-tracked through movement events.
- Store current state on `assets`; store every lifecycle change as an append-only movement row.
### 2. RBAC model for IT Center
- Keep current auth layers:
- `users.systemRole` for global authority
- workspace membership and active workspace session context for tenant authority
- Add a workspace-scoped business-role profile to membership-derived access:
- either a new membership field like `businessRole`
- or a dedicated per-organization user-access table linked to `user + organization`
- Recommended canonical permissions:
- `master_data:manage`
- `asset:read`
- `asset:create`
- `asset:update`
- `asset:assign`
- `asset:transfer`
- `asset:return`
- `asset:repair`
- `asset:audit`
- `report:read`
- Map business roles to permission bundles:
- `IT Admin`: full company-scoped access
- `Helpdesk`: assign/transfer/return/read
- `Infrastructure`: hardware, warranty, EOS/EOL/EOP, repair
- `Application`: software/license/subscription assets
- `Auditor`: read, audit, export/report read
- `Viewer`: read-only
- Keep server-side enforcement in route handlers and page guards; nav remains UX-only.
### 3. Feature/module structure in this repo
Create a new feature family under `src/features/assets/` and sibling dashboard routes under `src/app/dashboard/`:
- `src/features/assets/`
- `api/types.ts`
- `api/service.ts`
- `api/queries.ts`
- `api/mutations.ts`
- `components/`
- `schemas/`
- Add dashboard routes:
- `/dashboard/assets`
- `/dashboard/assets/[assetId]`
- `/dashboard/assets/assign`
- `/dashboard/assets/transfer`
- `/dashboard/assets/return`
- `/dashboard/assets/repair`
- `/dashboard/assets/history`
- Add master-data routes/pages, either grouped under `/dashboard/master-data/*` or `/dashboard/assets/settings/*`
- `sites`
- `departments`
- `locations`
- `employees`
- Reuse existing patterns:
- `PageContainer`
- TanStack Table
- TanStack Form + Zod
- React Query prefetch + `HydrationBoundary`
- route handlers in `src/app/api/**`
### 4. Backend and workflow design
Implement route handlers for:
- master data CRUD
- asset CRUD
- lifecycle actions as explicit endpoints, not generic updates:
- `POST /api/assets/[id]/assign`
- `POST /api/assets/[id]/transfer`
- `POST /api/assets/[id]/return`
- `POST /api/assets/[id]/repair`
- movement history listing:
- `GET /api/assets/[id]/movements`
- dashboard summary endpoints:
- totals by status
- warranty risk counts
- lifecycle risk counts
- data-quality counts
Behavior rules to lock in:
- `assign` updates current owner/location fields and inserts `ASSIGN` movement
- `transfer` updates user/department/location/code as needed and inserts one `TRANSFER` movement with old/new values
- `return` updates status to one of `IN_STOCK | REPAIR | RETIRED` and inserts `RETURN`
- `repair` inserts repair history and optionally sets status `REPAIR`
- every lifecycle mutation must write a movement record in the same server transaction
### 5. UI/navigation and documentation alignment
- Add new sidebar section for `Assets`, with visibility based on asset permissions.
- Keep `Workspaces` semantics unchanged; they still represent company switching.
- Add pages in this order for the MVP:
1. asset register/list
2. asset create/edit
3. assign
4. transfer
5. return
6. repair
7. movement history
8. dashboard summary widgets
9. master data CRUD pages
- Update stale docs while implementing:
- `docs/nav-rbac.md` is legacy Clerk-oriented and should be rewritten to match Auth.js + current session fields
- add a new domain glossary doc, preferably `CONTEXT.md`, to define:
- Organization = Company
- Site
- Department
- Location
- Employee
- Asset UID
- Asset Code
- Movement
- Business Role
## Public APIs / Types
- Add new feature contracts in `src/features/assets/api/types.ts`:
- `Asset`
- `AssetFilters`
- `AssetsResponse`
- `AssetMutationPayload`
- `AssetAssignmentPayload`
- `AssetTransferPayload`
- `AssetReturnPayload`
- `AssetRepairPayload`
- `AssetMovement`
- `AssetDashboardSummary`
- Add master data contracts:
- `Site`, `Department`, `Location`, `Employee`
- Extend workspace-scoped access modeling so session-backed access checks can resolve:
- current workspace business role
- current workspace asset permissions
- Do not overload `systemRole` with business roles.
## Test Plan
- Auth and tenancy:
- active organization scopes all master data and assets to one company
- switching organization changes visible assets and master data
- RBAC:
- `IT Admin` can do all asset operations in the active workspace
- `Helpdesk` can assign/transfer/return but cannot manage system settings
- `Infrastructure` can repair and manage lifecycle data
- `Auditor` can read and audit but cannot mutate assets
- `Viewer` cannot access transactional pages
- Asset lifecycle:
- create asset generates immutable `Asset UID`
- transfer can change owner, department, location, and asset code
- return updates status and writes movement
- repair writes repair history and status changes correctly
- History and risk:
- every lifecycle action creates a movement row
- warranty/EOS/EOL/EOP widgets count the right assets
- data-quality widgets flag missing user/location/serial/warranty
- UI:
- new nav items appear only for permitted roles
- asset list, detail, and transaction flows follow the repos React Query hydration pattern
## Assumptions and Defaults
- `organizations` remains the canonical tenant table and means `Company`.
- MVP phase 1 is the `Core Registry` only; `Audit`, advanced `Reports`, mobile scanning, approvals, and external integrations stay phase 2+.
- Business roles are workspace-scoped permission bundles layered on top of the current Auth.js + membership model.
- Hardware and software assets can share one `assets` table in MVP, using `assetType` and `assetCategory` fields, unless later scale forces separation.
- Movement history is the audit trail of lifecycle changes; it is not full event sourcing.

View File

@@ -1,429 +0,0 @@
# ALLA-ITCENTER
## Phase 1 - Asset Core MVP
Version: 1.0
Status: Approved Scope
---
# Objective
สร้าง Asset Single Source of Truth
ระบบต้องสามารถตอบได้ทันที
* Asset คืออะไร
* Asset อยู่ที่ไหน
* ใครถือครอง
* Asset เคยเปลี่ยน Code หรือไม่
* Asset เคยย้ายฝ่ายหรือไม่
---
# Scope
## Included
### Asset Master
### Assignment
### Transfer
### Return
### Movement History
### Dashboard
---
## Excluded
### Warranty
### EOS
### EOL
### EOP
### Audit
### Stock
### License
### Helpdesk
---
# Feature Structure
```text
src/features/
assets/
asset-assignments/
asset-transfers/
asset-movements/
asset-dashboard/
```
---
# Menu Structure
```text
Dashboard
Assets
├─ Asset List
├─ Asset Assignment
├─ Asset Transfer
└─ Asset Movements
```
---
# Asset Module
## Asset List
Route
```text
/dashboard/assets
```
Primary View
* Server-driven data table
* This is the canonical list UI for Asset records in Phase 1
* Must support desktop table layout and mobile-friendly responsive behavior
Functions
* Search
* Filter
* Sort
* Pagination
* Export
Columns
* Asset UID
* Asset Code
* Asset Name
* Category
* Company
* Department
* User
* Asset Status
* Asset Condition
* Disposition / Process Status
---
## Asset Detail
Route
```text
/dashboard/assets/[assetId]
```
Tabs
### Overview
### Assignment
### Movement Timeline
### Attachments
---
# Asset Assignment
Route
```text
/dashboard/assets/[assetId]/assign
```
Required Fields
* Asset
* Employee
* Department
* Location
* Assign Date
* Document Attachment
System Action
* Update Current Assignment
* Create Movement
---
# Asset Transfer
Route
```text
/dashboard/assets/[assetId]/transfer
```
Required Fields
* Old User
* New User
* Old Department
* New Department
* Old Location
* New Location
* Old Asset Code
* New Asset Code
* Transfer Date
* Reference Document
System Action
* Update Asset
* Create Movement
---
# Asset Return
Route
```text
/dashboard/assets/[assetId]/return
```
Required Fields
* Return Date
* Asset Condition
* Remark
System Action
* Asset Status = AVAILABLE
* Create Movement
---
# Status Model
Use these terms explicitly in UI, API contracts, database fields, filters, and dashboard labels.
## Asset Status
Current primary state of the asset.
```text
AVAILABLE
ASSIGNED
IN_REPAIR
LOST
RETIRED
```
## Asset Condition
Current physical condition of the asset.
```text
NORMAL
DAMAGED
```
## Disposition / Process Status
Current repair or write-off process state.
```text
NONE
WAITING_REPAIR
WAITING_WRITE_OFF
WRITE_OFF_COMPLETED
```
Status naming rules
* Do not use the word `Status` alone in requirements or UI labels
* `Asset Status` is the main status shown in the Asset Register Table
* `Asset Condition` is a separate field and filter
* `Disposition / Process Status` is a separate field and filter
* `Movement Type` belongs to timeline/history, not to the current-state status model
---
# Asset Movement
ทุก Event ต้องถูกบันทึก
Event Types
```text
CREATE
ASSIGN
TRANSFER
CHANGE_USER
CHANGE_LOCATION
CHANGE_DEPARTMENT
CHANGE_CODE
RETURN
```
---
# Dashboard
Route
```text
/dashboard
```
Cards
* Total Assets
* Assigned Assets
* In Stock Assets
* Transfer This Month
* Assets Without User
* Assets Without Location
---
# RBAC
## IT Admin
Full Access
---
## Helpdesk
* Read Asset
* Assign
* Transfer
* Return
---
## Infrastructure
* Read Asset
* Update Infrastructure Asset
---
## Viewer
Read Only
---
# API Scope
Assets
```text
GET /api/assets
GET /api/assets/:id
POST /api/assets
PUT /api/assets/:id
```
Assignments
```text
POST /api/assets/:id/assign
```
Transfers
```text
POST /api/assets/:id/transfer
```
Returns
```text
POST /api/assets/:id/return
```
Movements
```text
GET /api/assets/:id/movements
```
---
# UX Data Freshness Requirement
ทุก operation ที่เป็น CRUD ต้องทำให้ข้อมูลบนหน้าจอ "สด" หลัง action สำเร็จทันที
Rules
* Create: ต้อง refresh หรือ invalidate รายการที่เกี่ยวข้อง และอัปเดต detail view ถ้ามีการ redirect ไปหน้ารายละเอียด
* Update: ต้องอัปเดต detail cache และ refresh list cache ที่อาจได้รับผลกระทบจาก field ที่เปลี่ยน
* Delete: ต้องลบ item ออกจาก cache หรือ refetch list เพื่อไม่ให้ผู้ใช้เห็นข้อมูลค้าง
* Assignment, Transfer, Return: ต้อง refresh อย่างน้อย Asset Detail, Asset List, และ Movement Timeline
* Dashboard metrics/cards ที่ได้รับผลกระทบจาก mutation ต้องถูก refresh หลัง operation สำเร็จ
* ห้ามพึ่ง manual browser refresh เป็น flow ปกติของผู้ใช้
Implementation intent
* ใช้ TanStack Query `mutationOptions`
* กำหนด cache invalidation ใน `src/features/<name>/api/mutations.ts`
* ใช้ `invalidateQueries`, `setQueryData`, หรือ optimistic update ตามความเหมาะสม
* ทุก mutation ต้องมีแผน post-success cache synchronization ที่ชัดเจนเพื่อ UX ที่ดี
---
# Database Scope
Core Tables
```text
assets
asset_assignments
asset_movements
attachments
```
Reference Tables
```text
companies
sites
departments
locations
employees
```
---
# Success Criteria
ผู้ใช้งานสามารถค้นหา Asset และทราบได้ภายใน 30 วินาทีว่า
* Asset อยู่ที่ไหน
* ใครถือครอง
* เคยเปลี่ยนรหัสอะไร
* เคยย้ายฝ่ายหรือไม่
* เคยย้ายผู้ใช้หรือไม่
โดยไม่ต้องเปิด Excel หรือเอกสารกระดาษเพิ่มเติม

145
plans/task-a.md Normal file
View File

@@ -0,0 +1,145 @@
# Task A: Template Audit + Convention Freeze
## ALLA OS CRM vNext / Organization-based
คุณคือ Senior Full-stack Engineer + System Architect
ให้สำรวจ template project ปัจจุบันก่อนเริ่ม production code สำหรับ ALLA OS CRM vNext
## Context สำคัญ
ระบบนี้ต้องยึด **organization-based / workspace-based** เป็นแกนหลัก
```txt
organizationId = tenant / workspace / company group scope
membership = user role + permissions ภายใน organization
branchId = business branch / document scope ภายใน organization
```
ห้ามตีความ `branchId` เป็น tenant หลัก
ห้ามออกแบบแบบ branch-first
## ไฟล์/Skill ที่ต้องอ่านก่อน
ก่อนสรุป convention ต้องอ่าน:
```txt
.agents/skills/kiranism-shadcn-dashboard
Layout.md
AGENTS.md
README.md
package.json
src/db/schema.ts
src/lib/auth
src/app/dashboard
src/features
src/components
```
ถ้า path บางรายการไม่มี ให้ระบุใน audit ว่า “not found” ห้ามเดา
## เป้าหมาย
สร้างเอกสาร audit เพื่อ freeze convention ก่อนทำ Task B
## สิ่งที่ต้องตรวจ
1. Project structure
2. App Router structure
3. Dashboard layout
4. Layout rule จาก `Layout.md`
5. Skill rule จาก `.agents/skills/kiranism-shadcn-dashboard`
6. Sidebar / navigation pattern
7. PageContainer pattern
8. Server component / client component pattern
9. Data fetching pattern
10. TanStack Query / Hydration pattern
11. Form pattern
12. DataTable pattern
13. Sheet / Dialog / Drawer pattern
14. Drizzle schema convention
15. API route / server action convention
16. Feature folder convention
17. Auth convention
18. Organization context
19. Membership / permission / RBAC pattern
20. Active organization handling
21. Existing dashboard visual tone
22. Design token / theme usage
23. Files that should not be touched
24. Risk before Task B
## ข้อกำหนดสำคัญ
* ห้าม implement feature
* ห้าม refactor
* ห้ามเปลี่ยน config
* ห้ามเพิ่ม dependency
* ห้าม run build/test/lint จนกว่าจะได้รับคำสั่ง
* ห้ามสร้าง design system ใหม่
* ห้ามสร้าง layout ใหม่ถ้า template มีอยู่แล้ว
* ต้องยึด `Layout.md` และ dashboard skill เป็น source of truth ด้าน UI
## Output
สร้างไฟล์:
```txt
docs/implementation/task-a-template-audit.md
```
โครงสร้างเอกสาร:
```md
# Task A Template Audit
## 1. Executive Summary
## 2. Project Structure
## 3. Layout.md Findings
## 4. kiranism-shadcn-dashboard Skill Findings
## 5. Routing Convention
## 6. Dashboard Layout Convention
## 7. Feature Folder Convention
## 8. Component Convention
## 9. Form Convention
## 10. Table Convention
## 11. API / Server Action Convention
## 12. Drizzle / Database Convention
## 13. Auth Convention
## 14. Organization / Membership / Permission Convention
## 15. Branch Scope Convention
## 16. UI / Design Token Convention
## 17. CRM vNext Recommended Convention
## 18. Files That Should Not Be Touched
## 19. Risks / Concerns
## 20. Task B Implementation Plan
```
## Definition of Done
Task A ถือว่าเสร็จเมื่อ:
* มี audit document ครบ
* ยืนยันว่า organization-based เป็นแกนหลัก
* ยืนยันว่า branch เป็น sub-scope ภายใน organization
* ระบุ path สำหรับวาง Task B ได้ชัดเจน
* ระบุ convention UI จาก Layout.md และ dashboard skill แล้ว
* ยังไม่มี production feature ถูก implement

362
plans/task-b.md Normal file
View File

@@ -0,0 +1,362 @@
# Task B: Foundation Layer Implementation
## ALLA OS CRM vNext (Organization-Based)
คุณคือ Senior Full-stack Engineer
โปรด implement Foundation Layer สำหรับ ALLA OS CRM vNext โดยอ้างอิงผลจาก:
* docs/implementation/task-a-template-audit.md
* Layout.md
* .agents/skills/kiranism-shadcn-dashboard
## เป้าหมาย
สร้าง Foundation Layer ที่ทุก module ในอนาคตสามารถใช้ร่วมกันได้
Task B นี้ยังไม่ใช่ CRM Module
ยังไม่ต้องสร้าง:
* Customer
* Contact
* Enquiry
* Quotation
* Approval
* Dashboard KPI
* Report
* PDF Generator
---
# สิ่งที่ต้องอ่านก่อน
อ่านและยึดตาม:
```txt
docs/implementation/task-a-template-audit.md
Layout.md
.agents/skills/kiranism-shadcn-dashboard
src/auth.ts
src/lib/auth/**
src/db/schema.ts
src/features/products/**
src/features/users/**
```
ใช้ `products` และ `users` เป็น production reference
ห้ามใช้:
```txt
src/features/crm/**
src/constants/mock-api*
```
เป็น reference หลัก
---
# Scope 1: Current User Context
สร้าง shared helper
```ts
getCurrentUser()
requireCurrentUser()
getCurrentUserContext()
```
Expected output:
```ts
{
user,
activeOrganization,
membership,
permissions,
businessRole
}
```
Requirements:
* ใช้ Auth.js ของระบบ
* ใช้ session helper ที่มีอยู่แล้ว
* ห้าม duplicate auth logic
* ใช้ shared auth layer ของโปรเจ็ค
---
# Scope 2: Organization Context
สร้าง shared helper
```ts
getCurrentOrganization()
getActiveOrganizationId()
requireOrganizationAccess()
```
Requirements:
* ใช้ activeOrganizationId จากระบบเดิม
* ใช้ membership เดิม
* ใช้ organization เป็น tenant boundary
Business Rule:
```txt
ทุก CRM entity ในอนาคต
ต้องอยู่ภายใต้ organizationId
```
---
# Scope 3: Permission Layer
สร้าง helper
```ts
hasPermission(permission)
requirePermission(permission)
hasBusinessRole(role)
```
ตัวอย่าง:
```ts
hasPermission("crm.customer.create")
hasPermission("crm.quotation.approve")
```
Requirements:
* ใช้ memberships.permissions
* ใช้ businessRole
* ไม่สร้าง RBAC ใหม่
---
# Scope 4: Branch Scope
สร้าง helper
```ts
getUserBranches()
getActiveBranch()
validateBranchAccess()
```
Business Rule:
```txt
organization
├─ branch A
├─ branch B
└─ branch C
```
branch เป็น business scope
ไม่ใช่ tenant
Requirements:
* ยังไม่ต้องสร้าง CRM branch UI
* ยังไม่ต้อง migrate schema
* สร้างเฉพาะ abstraction layer
---
# Scope 5: Master Options Service
สร้าง service
```ts
getOptionsByCategory()
getActiveOptionsByCategory()
```
รองรับ category เช่น:
```txt
crm_customer_status
crm_customer_type
crm_enquiry_status
crm_quotation_status
crm_product_type
crm_currency
crm_payment_term
crm_priority
crm_lead_channel
```
Requirements:
* ใช้ ms_options schema
* รองรับ parent/child option
* รองรับ soft delete
* CRM module ในอนาคตห้าม hardcode status
---
# Scope 6: Document Sequence Service
สร้าง service
```ts
previewNextDocumentCode()
generateNextDocumentCode()
```
ตัวอย่าง:
```txt
CUS2606-001
ENQ2606-001
QT2606-001
```
Requirements:
* ใช้ document_sequences
* preview ห้าม increment
* generate ต้อง increment
* transaction-safe
* ห้าม generate code ฝั่ง client
---
# Scope 7: Audit Log Helper
สร้าง helper
```ts
auditCreate()
auditUpdate()
auditDelete()
auditAction()
```
Requirements:
* ใช้ tr_audit_logs
* รองรับ beforeData
* รองรับ afterData
* รองรับ requestId
* ทุก future mutation ต้องเรียกผ่าน helper นี้
---
# Folder Convention
ยึดตาม Task A
ถ้าไม่มี convention ที่ชัดเจน:
```txt
src/features/foundation/
├── auth-context/
├── organization-context/
├── permission/
├── branch-scope/
├── master-options/
├── document-sequence/
└── audit-log/
```
และทุก feature ใช้รูปแบบ:
```txt
api/
├── types.ts
├── service.ts
├── queries.ts
└── mutations.ts
```
ตาม kiranism-shadcn-dashboard
---
# UI Scope
ถ้าจำเป็นเท่านั้น
สร้างได้แค่:
```txt
/ dashboard/settings/master-options
```
สำหรับทดสอบ foundation
และต้อง:
* ใช้ PageContainer
* ใช้ Layout.md
* ใช้ theme token เดิม
* ใช้ DataTable เดิม
* ใช้ Sheet/Dialog เดิม
ห้ามสร้าง dashboard ใหม่
---
# ห้ามทำ
```txt
Customer CRUD
Contact CRUD
Enquiry CRUD
Quotation CRUD
Approval Workflow
Dashboard KPI
PDF Generator
Reporting
Notification
```
---
# Output
หลังเสร็จให้สรุป:
1. ไฟล์ที่เพิ่ม
2. ไฟล์ที่แก้ไข
3. Helper ที่สร้าง
4. Service ที่สร้าง
5. จุดที่ reuse จาก template
6. จุดที่ต้อง migration ในอนาคต
7. Risk
8. Task C readiness
---
# Definition of Done
Task B ถือว่าเสร็จเมื่อ:
✔ Current User Context ใช้งานได้
✔ Organization Context ใช้งานได้
✔ Permission Layer ใช้งานได้
✔ Branch Scope abstraction พร้อม
✔ Master Options Service พร้อม
✔ Document Sequence Service พร้อม
✔ Audit Log Helper พร้อม
✔ ยังไม่มี CRM business module ถูกสร้าง
✔ ไม่แก้ auth architecture เดิม
✔ ไม่สร้าง design system ใหม่
✔ พร้อมเริ่ม Task C: Customer + Contact