Project

General

Profile

Feature #26598 » spec.md

Parujee Pangsriuthai, 04/24/2026 04:32 PM

 
1
# เพิ่ม Field ในหน้า Employee Information
2

    
3
เพิ่ม field ใหม่ 5 ตัว + 2 computed fields ในหน้า Employee Information
4
เพื่อรองรับข้อมูล Section, Position, วันเข้างาน, วันเกิด และวันเกษียณ
5

    
6
> หมายเหตุ: Major (E/M) ใช้ field `department_incharge` ที่มีอยู่แล้วในระบบ ไม่ต้องเพิ่มใหม่
7

    
8
---
9

    
10
## Fields ใหม่ที่ต้องเพิ่ม
11

    
12
| Field | DB Column | Type | UI | Source | Required |
13
|---|---|---|---|---|---|
14
| Section | section_id | uuid → ms_code_table | ComboBox | code = 'section' | ไม่บังคับ |
15
| Position | position_id | uuid → ms_code_table | ComboBox | code = 'position' | ไม่บังคับ |
16
| วันเข้างาน | hire_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
17
| วันเกิด | birth_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
18
| วันเกษียณ | retirement_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
19
| อายุงาน | - | computed | แสดงอย่างเดียว | NOW() - hire_date | - |
20
| อายุคน | - | computed | แสดงอย่างเดียว | NOW() - birth_date | - |
21

    
22
---
23

    
24
## ตำแหน่งใน Form
25

    
26
เพิ่มเป็น section ใหม่ "Personal Information" ใต้ section "Employee Detail"
27

    
28
```
29
Section: Personal Information
30

    
31
Row 1:  [ Section (ComboBox) ]       [ Position (ComboBox) ]
32
Row 2:  [ Hire Date (DatePicker) ]   [ Birth Date (DatePicker) ]   [ Retirement Date (DatePicker) ]
33
Row 3:  [ อายุงาน (read-only) ]      [ อายุคน (read-only) ]
34
```
35

    
36
---
37

    
38
## DB Migration
39

    
40
```sql
41
ALTER TABLE ms_employee
42
  ADD COLUMN section_id uuid REFERENCES ms_code_table(id),
43
  ADD COLUMN position_id uuid REFERENCES ms_code_table(id),
44
  ADD COLUMN hire_date date,
45
  ADD COLUMN birth_date date,
46
  ADD COLUMN retirement_date date;
47
```
48

    
49
### Code Table ที่ต้องเพิ่ม
50

    
51
**Section** (code = 'section')
52
- ค่าจาก feedback เช่น PSO/EGM/EGMDC/EGMDC3, PSO/EGM/EGMBD/EGMBD1 ฯลฯ
53

    
54
**Position** (code = 'position')
55
- Senior Staff, หัวหน้างาน, พนักงานสำนักงาน ฯลฯ
56

    
57
---
58

    
59
## Frontend
60

    
61
### Schema (employee-form.schema.ts)
62

    
63
เพิ่มใน zod schema:
64
```typescript
65
section_id: z.string().nullable(),
66
position_id: z.string().nullable(),
67
hire_date: z.string().nullable(),
68
birth_date: z.string().nullable(),
69
retirement_date: z.string().nullable(),
70
```
71

    
72
### Form (EmployeeForm.tsx)
73

    
74
- เพิ่ม FormSection "Personal Information"
75
- เพิ่ม FormComboBox → section_id, position_id
76
- เพิ่ม FormDatePicker → hire_date, birth_date, retirement_date
77
- เพิ่ม read-only display → อายุคน, อายุงาน
78

    
79
### Hook (useMasterEmployeeForm.ts)
80

    
81
เพิ่ม fetch select list:
82
- sectionSelectList → GET /v1/code-table?code=section
83
- positionSelectList → GET /v1/code-table?code=position
84

    
85
### คำนวณอายุ (Frontend)
86
```typescript
87
const calculateAge = (dateStr: string | null): string => {
88
  if (!dateStr) return "-";
89
  const years = ((Date.now() - new Date(dateStr).getTime()) / (365.25 * 24 * 60 * 60 * 1000)).toFixed(1);
90
  return `${years} ปี`;
91
};
92
```
93

    
94
---
95

    
96
## Backend
97

    
98
### CRUD
99
- เพิ่ม field ใหม่ใน Create/Update DTO: section_id, position_id, hire_date, birth_date, retirement_date
100

    
101
### Select List
102
- ใช้ code_table API ที่มีอยู่แล้ว ไม่ต้องสร้าง endpoint ใหม่
103

    
104
---
105

    
106
## ข้อมูลจาก Feedback Excel
107

    
108
ไฟล์ `Call_system_username-role_260424_feedback.xlsx` มีข้อมูลพนักงาน ~100 คน
109
จะใช้ gen SQL เพื่อ:
110
1. INSERT code_table entries สำหรับ section, position
111
2. UPDATE ms_employee ใส่ค่า field ใหม่ตามข้อมูลใน Excel
112

    
113
---
114

    
115
## Naming Convention
116

    
117
| Field เดิมในระบบ | Pattern | Field ใหม่ |
118
|---|---|---|
119
| department_id | xxx_id (uuid FK) | section_id, position_id |
120
| - | xxx_date (date) | hire_date, birth_date, retirement_date |
(2-2/3)