# เพิ่ม Field ในหน้า Employee Information

เพิ่ม field ใหม่ 5 ตัว + 2 computed fields ในหน้า Employee Information
เพื่อรองรับข้อมูล Section, Position, วันเข้างาน, วันเกิด และวันเกษียณ

> หมายเหตุ: Major (E/M) ใช้ field `department_incharge` ที่มีอยู่แล้วในระบบ ไม่ต้องเพิ่มใหม่

---

## Fields ใหม่ที่ต้องเพิ่ม

| Field | DB Column | Type | UI | Source | Required |
|---|---|---|---|---|---|
| Section | section_id | uuid → ms_code_table | ComboBox | code = 'section' | ไม่บังคับ |
| Position | position_id | uuid → ms_code_table | ComboBox | code = 'position' | ไม่บังคับ |
| วันเข้างาน | hire_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
| วันเกิด | birth_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
| วันเกษียณ | retirement_date | date | DatePicker | กรอกเอง | ไม่บังคับ |
| อายุงาน | - | computed | แสดงอย่างเดียว | NOW() - hire_date | - |
| อายุคน | - | computed | แสดงอย่างเดียว | NOW() - birth_date | - |

---

## ตำแหน่งใน Form

เพิ่มเป็น section ใหม่ "Personal Information" ใต้ section "Employee Detail"

```
Section: Personal Information

Row 1:  [ Section (ComboBox) ]       [ Position (ComboBox) ]
Row 2:  [ Hire Date (DatePicker) ]   [ Birth Date (DatePicker) ]   [ Retirement Date (DatePicker) ]
Row 3:  [ อายุงาน (read-only) ]      [ อายุคน (read-only) ]
```

---

## DB Migration

```sql
ALTER TABLE ms_employee
  ADD COLUMN section_id uuid REFERENCES ms_code_table(id),
  ADD COLUMN position_id uuid REFERENCES ms_code_table(id),
  ADD COLUMN hire_date date,
  ADD COLUMN birth_date date,
  ADD COLUMN retirement_date date;
```

### Code Table ที่ต้องเพิ่ม

**Section** (code = 'section')
- ค่าจาก feedback เช่น PSO/EGM/EGMDC/EGMDC3, PSO/EGM/EGMBD/EGMBD1 ฯลฯ

**Position** (code = 'position')
- Senior Staff, หัวหน้างาน, พนักงานสำนักงาน ฯลฯ

---

## Frontend

### Schema (employee-form.schema.ts)

เพิ่มใน zod schema:
```typescript
section_id: z.string().nullable(),
position_id: z.string().nullable(),
hire_date: z.string().nullable(),
birth_date: z.string().nullable(),
retirement_date: z.string().nullable(),
```

### Form (EmployeeForm.tsx)

- เพิ่ม FormSection "Personal Information"
- เพิ่ม FormComboBox → section_id, position_id
- เพิ่ม FormDatePicker → hire_date, birth_date, retirement_date
- เพิ่ม read-only display → อายุคน, อายุงาน

### Hook (useMasterEmployeeForm.ts)

เพิ่ม fetch select list:
- sectionSelectList → GET /v1/code-table?code=section
- positionSelectList → GET /v1/code-table?code=position

### คำนวณอายุ (Frontend)
```typescript
const calculateAge = (dateStr: string | null): string => {
  if (!dateStr) return "-";
  const years = ((Date.now() - new Date(dateStr).getTime()) / (365.25 * 24 * 60 * 60 * 1000)).toFixed(1);
  return `${years} ปี`;
};
```

---

## Backend

### CRUD
- เพิ่ม field ใหม่ใน Create/Update DTO: section_id, position_id, hire_date, birth_date, retirement_date

### Select List
- ใช้ code_table API ที่มีอยู่แล้ว ไม่ต้องสร้าง endpoint ใหม่

---

## ข้อมูลจาก Feedback Excel

ไฟล์ `Call_system_username-role_260424_feedback.xlsx` มีข้อมูลพนักงาน ~100 คน
จะใช้ gen SQL เพื่อ:
1. INSERT code_table entries สำหรับ section, position
2. UPDATE ms_employee ใส่ค่า field ใหม่ตามข้อมูลใน Excel

---

## Naming Convention

| Field เดิมในระบบ | Pattern | Field ใหม่ |
|---|---|---|
| department_id | xxx_id (uuid FK) | section_id, position_id |
| - | xxx_date (date) | hire_date, birth_date, retirement_date |
