Create Round from Template
สร้างงวดโอทีจาก Template ที่บันทึกรูปแบบไว้ล่วงหน้า
ระบบจะคำนวณช่วงวันที่ของงวดให้เองตามที่ตั้งไว้ใน Template จึงเหมาะกับ automation รายเดือน — ตั้ง Template ครั้งเดียว แล้วเรียก API นี้ทุกเดือนโดยเปลี่ยนแค่ year_month สร้างได้หลายรอบพร้อมกันโดยส่ง Template หลายตัวใน template_ids
Endpoint
POST /api/v1/open-apis/calculation-ot/create-ot-round-from-templateสิทธิ์ที่ต้องการ: API Key ต้องมีสิทธิ์ ข้อมูลเงินเดือนทั้งองค์กร (payroll:read:all)
Request Parameters
Required Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
year_month | string | Yes | งวดเงินเดือนที่รอบจะสังกัด (YYYY-MM) | 2026-09 |
template_ids | array | Yes | รายการรหัส Template ที่ต้องการสร้าง (ได้จาก List OT Templates) | ["20251127T8891F6A3D024"] |
template_ids เป็น array — สมาชิกใน array ต้องใช้ค่า raw เท่านั้น ห้ามเข้ารหัส Base64 เพราะระบบเข้ารหัสให้เอง (ต่างจาก master_salary_ot_report_template_id ที่ส่งเป็นพารามิเตอร์เดี่ยวและต้องเป็น Base64) และรหัส Template ที่หาไม่พบจะถูกข้ามเงียบ ๆ ไม่เป็น error
Request Body Example
{
"year_month": "2026-09",
"template_ids": [
"20251127T8891F6A3D024"
]
}Response Format
Success Response (HTTP 200)
{
"code": 200,
"message": "Create OT round from template (2026-09) Accept",
"payload": [
{
"master_salary_ot_report_id": "20251127D4573C421639",
"master_salary_month": "2026-09",
"master_salary_ot_name": "งวดโอที ก.ย. 2026",
"ot_report_start_dt": "2026-08-21 00:00:00",
"ot_report_end_dt": "2026-09-20 23:59:59",
"ot_day_in_month": 31
}
]
}Error Response - Salary Period Not Found (HTTP 400)
{
"code": 400,
"message": "ไม่สำเร็จ",
"payload": []
}วิธีแก้: สร้างงวดเงินเดือนของเดือนนั้นก่อน
Error Response - Validation Failed (HTTP 400)
{
"code": 400,
"message": "ไม่สำเร็จ",
"errors": [
"กรุณาระบุ 'template_ids' (array ของรหัส template)"
]
}วิธีแก้: ส่ง template_ids เป็น array และมีอย่างน้อยหนึ่งรายการ
Error Response - Unauthorized (HTTP 401)
{
"code": 401,
"message": "Unauthorized",
"payload": []
}วิธีแก้: ตรวจสอบว่า API Key ถูกต้องและมีสิทธิ์ตามที่ระบุไว้ด้านบน — ดูวิธีตั้งค่าได้ที่ Get Started
Response Fields
| Field | Type | Description |
|---|---|---|
payload | array | รายการงวดที่สร้างสำเร็จ หนึ่งรายการต่อหนึ่ง Template |
payload[].master_salary_ot_report_id | string | รหัสรอบที่สร้าง — เก็บไว้ใช้สั่งคำนวณต่อ |
payload[].master_salary_month | string | งวดเดือนที่รอบนี้สังกัด |
payload[].master_salary_ot_name | string | ชื่อรอบที่ระบบตั้งจาก Template |
payload[].ot_report_start_dt | string | วันเริ่มรอบที่ระบบคำนวณจาก Template |
payload[].ot_report_end_dt | string | วันสิ้นรอบที่ระบบคำนวณจาก Template |
payload[].ot_day_in_month | int | จำนวนวันในรอบ |
Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/calculation-ot/create-ot-round-from-template" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"year_month": "2026-09",
"template_ids": [
"20251127T8891F6A3D024"
]
}'Validation Rules
| Parameter | Validation | Error Message |
|---|---|---|
year_month | ต้องเป็นรูปแบบ YYYY-MM และมีงวดเงินเดือนของเดือนนั้นอยู่แล้ว | 'year_month' ต้องเป็นรูปแบบ YYYY-MM |
template_ids | ต้องเป็น array และมีอย่างน้อยหนึ่งรายการ | กรุณาระบุ 'template_ids' (array ของรหัส template) |
Notes
- รอบที่สร้างจะยังไม่มีพนักงาน ต้องเรียก Assign Employees ต่อ
- Template กำหนดได้ว่าเริ่มวันที่เท่าไร จบวันที่เท่าไร และเลื่อนไปกี่เดือนจากงวดเงินเดือน ระบบจึงคำนวณวันที่จริงให้ตาม
year_monthที่ส่งมา - Template ที่ตั้งวันจบเป็นสิ้นเดือน (
EOM) ระบบจะคิดจำนวนวันของเดือนนั้นให้อัตโนมัติ
Related APIs
- List OT Templates - หารหัส Template ที่มีอยู่
- Assign Employees - เพิ่มพนักงานเข้างวดที่สร้าง
- Calculate OT - สั่งคำนวณโอทีรายคนในรอบนี้