v5 Master: Inventory
Dynamic Document API สำหรับข้อมูลสินค้า — รวมถึงบาร์โค้ด, หน่วยนับ, คลัง, ราคา, ชื่อสำหรับบิล/POS/ตลาด, สี/ขนาด/รูปแบบ, ผู้ผลิต, สินค้าทดแทน, สินค้าพ่วง
Module
ic.inventory
EndPoint
POST /SMLJavaRESTService/v5/api/documents/ic.inventory
GET /SMLJavaRESTService/v5/api/documents/ic.inventory/{code}❗ ตอนนี้รองรับเฉพาะ POST (สร้างใหม่) กับ GET (อ่าน) เท่านั้น — ยังไม่มี UPDATE / DELETE
Table Mapping
ทุก sub-section คืน array เสมอ (multiple = true) ถึงแม้บางตารางจะมี row เดียวต่อสินค้า
| # | Section | Table | Parent key (header → child) | หมายเหตุ |
|---|---|---|---|---|
| - | header | ic_inventory | (key: code) | required |
| 1 | details | ic_inventory_detail | code → ic_code | รายละเอียด/setting เพิ่มเติม |
| 2 | barcodes | ic_inventory_barcode | code → ic_code | บาร์โค้ด, หน่วย, ราคาขาย |
| 3 | units | ic_unit_use | code → ic_code | หน่วยนับที่ใช้กับสินค้า |
| 4 | warehouses | ic_wh_shelf | code → ic_code | คลัง/ที่เก็บของสินค้า |
| 5 | standard_costs | ic_standard_cost | code → ic_code | ต้นทุนมาตรฐาน |
| 6 | name_billing | ic_name_billing | code → ic_code | ชื่อสำหรับออกบิล |
| 7 | name_market | ic_name_merket ⚠️ | code → ic_code | ชื่อทางการตลาด (table สะกดผิดใน DB จริง) |
| 8 | name_short | ic_name_short | code → ic_code | ชื่อย่อ |
| 9 | name_pos | ic_name_pos | code → ic_code | ชื่อสำหรับขายหน้าร้าน (POS) |
| 10 | color_use | ic_color_use | code → ic_code | สีสินค้าที่ใช้ |
| 11 | size_use | ic_size_use | code → ic_code | ขนาดสินค้าที่ใช้ |
| 12 | pattern_use | ic_pattern_use | code → ic_code | รูปแบบสินค้าที่ใช้ |
| 13 | manufacturers | ic_manufacturer_list | code → ic_code | ผู้ผลิตของสินค้า |
| 14 | replacements | ic_inventory_replacement | code → ic_replace_code | สินค้าทดแทน — ic_replace_code คือสินค้าหลัก, ic_code คือสินค้าทดแทน |
| 15 | bundles | ic_inventory_bundle | code → ic_code_bundle | สินค้าพ่วง — ic_code_bundle คือสินค้าหลัก, ic_code คือสมาชิกใน bundle |
POST Example
ส่งได้หลายสินค้าพร้อมกันใน items[] โดยแต่ละ item มี header เป็นบังคับ ส่วน sub-section อื่น ๆ ส่งเฉพาะที่ต้องการ
ตัวอย่างเต็ม (ครบทุก section)
{
"items": [
{
"header": {
"code": "ITEM260609001",
"name_1": "สินค้าทดสอบ A",
"name_eng_1": "Test Item A",
"item_type": 0,
"item_category": "CAT01",
"group_main": "GRP01",
"unit_type": 0,
"status": 0
},
"details": [
{
"po_over": 0,
"so_over": 0,
"account_group": "ACC01",
"unit_for_stock": "PCS"
}
],
"barcodes": [
{
"barcode": "8851234567890",
"unit_code": "PCS",
"price": 100,
"price_2": 95,
"price_3": 90,
"price_4": 85
},
{
"barcode": "8851234567891",
"unit_code": "BOX",
"price": 1200
}
],
"units": [
{ "unit_code": "PCS", "stand_value": 1, "divide_value": 1 },
{ "unit_code": "BOX", "stand_value": 12, "divide_value": 1 }
],
"warehouses": [
{ "wh_code": "CENTER", "shelf_code": "A01" },
{ "wh_code": "BRANCH01", "shelf_code": "B05" }
],
"standard_costs": [
{ "cost": 60 }
],
"name_billing": [
{ "name": "สินค้าทดสอบ A (สำหรับบิล)" }
],
"name_market": [
{ "name": "สินค้าทดสอบ A (การตลาด)" }
],
"name_short": [
{ "name": "สนค A" }
],
"name_pos": [
{ "name": "สินค้า A (POS)" }
],
"color_use": [
{ "color_code": "RED" },
{ "color_code": "BLUE" }
],
"size_use": [
{ "size_code": "S" },
{ "size_code": "M" },
{ "size_code": "L" }
],
"pattern_use": [
{ "pattern_code": "STRIPE" }
],
"manufacturers": [
{ "manufacturer_code": "MFG01" }
],
"replacements": [
{ "ic_code": "ITEM260609002" }
],
"bundles": [
{ "ic_code": "ITEM260609003", "unit_code": "PCS", "qty": 1 },
{ "ic_code": "ITEM260609004", "unit_code": "PCS", "qty": 2 }
]
}
]
}ตัวอย่างขั้นต่ำ (เฉพาะสินค้าใหม่ + บาร์โค้ดเดียว)
{
"items": [
{
"header": {
"code": "ITEM260609010",
"name_1": "สินค้าเดี่ยว",
"item_type": 0,
"status": 0
},
"barcodes": [
{ "barcode": "8851234599999", "unit_code": "PCS", "price": 50 }
]
}
]
}Response Success
{
"success": true,
"data": {
"items": [
{
"header": { "code": "ITEM260609001", "...": "..." },
"details": [ { "ic_code": "ITEM260609001", "...": "..." } ],
"barcodes": [ { "ic_code": "ITEM260609001", "barcode": "...", "...": "..." } ],
"...": "..."
}
]
}
}ระบบจะเติม
ic_code(หรือic_replace_code/ic_code_bundleแล้วแต่ section) ให้อัตโนมัติจากheader.code— ส่งมาเองก็ได้ แต่ไม่ส่งก็ใช้ได้
GET Example
GET http://localhost:8086/SMLJavaRESTService/v5/api/documents/ic.inventory/ITEM260609001{
"success": true,
"data": {
"items": [
{
"header": {
"code": "ITEM260609001",
"name_1": "สินค้าทดสอบ A",
"item_type": 0,
"status": 0
},
"details": [
{ "ic_code": "ITEM260609001", "po_over": 0, "so_over": 0 }
],
"barcodes": [
{
"ic_code": "ITEM260609001",
"barcode": "8851234567890",
"unit_code": "PCS",
"price": 100
}
],
"units": [
{ "ic_code": "ITEM260609001", "unit_code": "PCS", "stand_value": 1, "divide_value": 1 }
],
"warehouses": [
{ "ic_code": "ITEM260609001", "wh_code": "CENTER", "shelf_code": "A01" }
],
"replacements": [
{ "ic_replace_code": "ITEM260609001", "ic_code": "ITEM260609002" }
],
"bundles": [
{ "ic_code_bundle": "ITEM260609001", "ic_code": "ITEM260609003", "unit_code": "PCS", "qty": 1 }
]
}
]
}
}- Section ที่ไม่มีข้อมูลใน DB จะ ไม่ปรากฏ ใน response (ไม่ใช่ array ว่าง)
- Section ที่มีข้อมูล จะคืนเป็น array เสมอ
Rules / ข้อสำคัญ
| เรื่อง | รายละเอียด |
|---|---|
| Required | header กับ header.code ต้องส่งทุกครั้ง |
| Auto-fill | ระบบเติม parent key column (ic_code, ic_replace_code, ic_code_bundle) จาก header.code ให้อัตโนมัติถ้าไม่ส่งมา |
line_number | ถ้าไม่ส่ง ระบบจะรันให้อัตโนมัติเริ่มที่ 1 |
| Field invalid | ส่ง field ที่ไม่มีในตารางจะคืน error FIELD_NOT_FOUND พร้อมชื่อ field และตาราง |
| Section ผิด format | ทุก sub-section ต้องเป็น array — ส่ง object ตรง ๆ จะคืน INVALID_SECTION |
| ตารางไม่มีใน DB | ถ้า provider/database ไม่มีตารางที่ register ไว้ (เช่น บาง version) ระบบจะคืน TABLE_NOT_FOUND |
| Transaction | INSERT ทุก section อยู่ใน transaction เดียว — error ใด ๆ rollback ทั้งหมด |
ตาราง ic_name_merket | ตามฐานข้อมูลจริงสะกดผิด (merket ไม่ใช่ market) — manifest คงไว้ตามนั้น |
ตารางที่ยัง ไม่ได้ รวมใน manifest นี้
ตารางต่อไปนี้เกี่ยวข้องกับสินค้าแต่ยังไม่ได้ register เพราะต้องการ logic พิเศษ:
| ตาราง | เหตุผล |
|---|---|
ic_inventory_suggest | ใช้ bi-directional cleanup (ic_suggest_code OR ic_code) — framework ยังไม่รองรับ |
ic_opposite_unit | เฉพาะบาง version (SMLAccountProfessional, SMLAccount, SMLAccountPOSProfessional, SMLCM) — ยังไม่มีระบบ filter version ใน v5 |
m_druginteraction | เฉพาะ version SMLPOSMED + bi-directional cleanup |
ถ้าจำเป็นต้องใช้ในอนาคต ต้องขยาย SectionManifest ให้รองรับ bi-directional key + version tag ก่อน