แก้ไขใบเสร็จแบบแบ่งชำระแบบ Simple
ใช้ endpoint PUT /receipts/{id} เพื่อแก้ไขใบเสร็จรับเงินแบบแบ่งชำระที่สร้างไว้แล้ว
โดยรองรับเฉพาะใบเสร็จแบบ Simple ที่มีสถานะ รอดำเนินการ (Awaiting) เท่านั้น
ปัจจุบันรองรับเฉพาะการแก้ไขใบเสร็จแบบ Simple เท่านั้น ใบเสร็จแบบ Inline ยังไม่รองรับการแก้ไขผ่าน OpenAPI
Request field
Required field ระดับเอกสาร
| Field | ประเภท | คำอธิบาย |
|---|---|---|
contactId | integer (int64) | รหัสผู้ติดต่อ — ต้องตรงกับรหัสผ ู้ติดต่อของใบกำกับภาษีต้นทาง |
isBatchDocument | boolean | ต้องเป็น true เสมอ — ระบุว่าเป็นเอกสารแบบแบ่งชำระ |
partialPaymentMethod | number | ต้องเป็น 11 (RECPartial) |
creditType | number | ต้องเป็น 3 (เงินสด) ค่าอื่นไม่รองรับสำหรับใบเสร็จแบบแบ่งชำระ |
documentStructureType | string | ต้องเป็น "UpdateSimpleDocument" |
grandTotal | decimal | ต้องเท่ากับ partialAmount |
documentReference | array | ต้องเป็น null หรือ [] เท่านั้น |
Required field ระดับรายการสินค้า
| Field | ประเภท | คำอธิบาย |
|---|---|---|
documentId | number | recordId ของใบกำกับภาษีต้นทาง — ต้องตรงกับ recordId ของใบกำกับภาษีเดิมที่สร้างไว้ |
documentType | number | ต้องเป็น 7 (ใบกำกับภาษี) |
partialAmount | decimal | ยอดที่ต้องการชำระในงวดนี้ (ต้องมากกว่า 0 และไม่เกินยอดคงเหลือ) |
Field เพิ่มเติม (ไม่บังคับ)
ข้อมูลผู้ติดต่อ
| Field | ประเภท | คำอธิบาย |
|---|---|---|
contactName | string | ชื่อผู้ติดต่อ |
contactCode | string | รหัสลูกค้า |
contactAddress | string | ที่อยู่ |
contactTaxId | string | เลขประจำตัวผู้เสียภาษี (13 หลัก) |
contactBranch | string | สาขา |
contactPerson | string | ชื่อผู้ติดต่อ |
contactEmail | string | อีเมล |
contactNumber | string | เบอร์โทรศัพท์ |
contactZipCode | string | รหัสไปรษณีย์ |
contactGroup | integer | ประเภทผู้ติดต่อ |
field ข้อมูลผู้ติดต่อ — หากระบุค่ามาจะต้องตรงกับข้อมูลจากใบกำกับภาษีต้นทาง โดยระบบจะดึงค่าจากใบกำกับภาษีให้อัตโนมัติหากไม่ระบุ
ข้อมูลเอกสาร
| Field | ประเภท | คำอธิบาย |
|---|---|---|
dueDate | string (date) | วันครบกำหนด (yyyy-MM-dd) |
publishedOn | string (date) | วันที่ออกเอกสาร (yyyy-MM-dd) |
creditDays | integer | จำนวนวันเครดิต |
salesName | string | ชื่อพนักงานขาย |
reference | string | เลขอ้างอิงจากระบบภายนอก |
projectName | string | ชื่อโครงการ |
remarks | string | หมายเหตุ |
internalNotes | string | บันทึกภายใน |
externalDocumentId | string | รหัสเอกสารจากระบบภายนอก |
showSignatureOrStamp | boolean | แสดงพื้นที่ลายเซ็น/ตรา |
การหักเงิน
| Field | ประเภท | คำอธิบาย |
|---|---|---|
useReceiptDeduction | boolean | ใช้การหักเงิน (ค่าเริ่มต้น: false) |
documentDeductionType | integer | ประเภทการหักเงิน |
documentDeductionAmount | number (decimal) | จำนวนเงินที่หัก |
การตรวจสอบยอดเงิน
เมื่อมีการแก้ไขใบเสร็จแบบแบ่งชำระ ระบบจะทำการตรวจสอบว่า
จำนวนเงินที่ระบุ (partialAmount) ต้องไม่เกิน ยอดคงเหลือ ของใบกำกับภาษี
หลักการคำนวณยอดคงเหลือ
ยอดคงเหลือ = ยอดรวมของใบกำกับภาษี (INV) − ยอดรวมของใบเสร็จอื่นที่ยังใ ช้งานอยู่
ระบบจะไม่รวมยอดเดิมของใบเสร็จที่กำลังแก้ไข เพื่อให้สามารถปรับแก้จำนวนเงินได้อย่างถูกต้อง
ตัวอย่างการคำนวณ
ใบกำกับภาษีมียอดรวม 321 บาท มีใบเสร็จแบบแบ่งชำระจำนวน 2 ใบ ดังนี้:
- ใบเสร็จ RE-1: 50 บาท
- ใบเสร็จ RE-2 (อยู่ระหว่างการแก้ไข): 100 บาท
ผลการคำนวณ
| รายการ | ยอด (บาท) |
|---|---|
| ยอดรวม INV | 321 |
| หัก RE-1 (ฉบับอื่น) | -50 |
| หัก RE-2 (ฉบับที่ก ำลังแก้ไข) | ไม่นับรวม |
| ยอดคงเหลือ | 271 |
ดังนั้น จำนวนเงิน (partialAmount) ที่แก้ไขใหม่ ต้องมีค่าไม่เกิน 271 บาท
ตัวอย่างการแก้ไขใบเสร็จแบบแบ่งชำระ
Scenario ต้องการแก้ไขใบเสร็จ RE2026030079 (ยอดเดิม 100 บาท) จากใบกำกับภาษี INV2026030045 (ยอดรวม 321 บาท) โดยปรับยอดชำระจาก 100 บาท เป็น 50 บาท
Endpoint: PUT /receipts/{id}
field ที่ถูกไฮไลท์ในตัวอย่างข้อมูลที่ส่งและข้อมูลที่ตอบกลับ คือ field ที่เกี่ยวข้องกับการแก้ไขใบเสร็จแบบแบ่งชำระโดยเฉพาะ
ตัวอย่าง Payload แบบย่อ
ตัวอย่าง request แบบระบุเฉพาะ field ที่จำเป็นเท่านั้น
{
"contactId": 76742433,
"isBatchDocument": true,
"partialPaymentMethod": 11,
"creditType": 3,
"documentStructureType": "UpdateSimpleDocument",
"grandTotal": 50,
"items": [
{
"documentId": 84130351,
"documentType": 7,
"partialAmount": 50
}
]
}
ตัวอย่าง Payload แบบเต็ม
ตัวอย่าง request แบบระบุ field ทั้งหมดที่รองรับ สำหรับใช้เป็นแนวทางในการส่งข้อมูล
{
"contactId": 490472,
"contactName": "ContactName",
"contactCode": "",
"contactAddress": "11/12 Example Rd, Silom, Bang Rak, Bangkok",
"contactTaxId": "1234567890123",
"contactBranch": "สำนักงานใหญ่",
"contactPerson": "ExamplePerson",
"contactEmail": "Example@email.com",
"contactNumber": "0876543210",
"contactZipCode": "10500",
"contactGroup": 1,
"publishedOn": "2026-03-12",
"dueDate": "2026-03-12",
"isBatchDocument": true,
"partialPaymentMethod": 11,
"creditType": 3,
"creditDays": 0,
"grandTotal": 50,
"documentStructureType": "UpdateSimpleDocument",
"documentReference": [],
"useReceiptDeduction": true,
"documentDeductionType": 1,
"documentDeductionAmount": 10,
"salesName": "ExampleSalesName",
"reference": "ExampleReference",
"projectName": "ExampleProject",
"remarks": "งวดที่ 2 - ปรับยอดจาก 20 เป็น 50",
"internalNotes": "Updated per customer request",
"externalDocumentId": "test-xxx01",
"showSignatureOrStamp": true,
"items": [
{
"documentId": 9962945,
"documentType": 7,
"partialAmount": 50
}
]
}
Response (200 OK)
แสดงเฉพาะ field ที่เกี่ยวข้องกับใบเสร็จแบบแบ่งชำระ — field อื่นที่ไม่ได้แสดงจะตอบกลับเหมือนใบเสร็จรับเงินปกติ
{
"data": {
"items": [
{
"documentId": 9962945,
"documentType": 7,
"documentSerial": "INV2026030045",
"documentPublishedOn": "2026-03-12T00:00:00",
"documentDuedate": "2026-03-12T00:00:00",
"documentGrandTotal": 321.0,
"documentPaymentAmount": 321.0,
"partialAmount": 50.0
}
],
"status": "1",
"documentType": "9",
"publishedOn": "2026-03-12T00:00:00",
"creditType": "3",
"grandTotal": "50",
"useReceiptDeduction": "true",
"documentDeductionType": "1",
"documentDeductionAmount": "10",
"referencedByMe": [
{
"referenceId": "9962945",
"referenceDocumentType": "7",
"referenceDocumentSerial": "INV2026030045",
"documentId": "66603",
"documentType": "9",
"documentSerial": "RE2026030079",
"type": 11
}
],
"recordId": 66603,
"documentId": 66603,
"documentSerial": "RE2026030079",
"statusString": "awaiting",
"isBatchDocument": true
},
"status": true,
"message": "",
"code": 0
}
การเปลี่ยนสถานะของใบกำกับภาษีต้นทาง (INV) หลังแก้ไข
หลังจากแก้ไขใบเสร็จแบบแบ่งชำระสำเร็จ ระบบจะคำนวณยอดรวมทั้งหมดของใบเสร็จรับเงินที่ใช้งานอยู่ใหม่ และอัปเดตสถานะของใบกำกับภาษีต้นทางโดยอัตโนมัติ
| เงื่อนไข | ผลลัพธ์ต่อ INV |
|---|---|
ยอดรวม RE ทั้งหมด < grandTotal ของ INV | INV ยังคงสถานะ แบ่งจ่าย (status=11) |
ยอดรวม RE ทั้งหมด = grandTotal ของ INV | INV เปลี่ยนสถานะเป็น เปิดใบเสร็จแล้ว (status=9) |