Skip to content

v5 Master: Inventory

Dynamic Document API สำหรับข้อมูลสินค้า — รวมถึงบาร์โค้ด, หน่วยนับ, คลัง, ราคา, ชื่อสำหรับบิล/POS/ตลาด, สี/ขนาด/รูปแบบ, ผู้ผลิต, สินค้าทดแทน, สินค้าพ่วง

Module

ic.inventory

EndPoint

http
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 เดียวต่อสินค้า

#SectionTableParent key (header → child)หมายเหตุ
-headeric_inventory(key: code)required
1detailsic_inventory_detailcodeic_codeรายละเอียด/setting เพิ่มเติม
2barcodesic_inventory_barcodecodeic_codeบาร์โค้ด, หน่วย, ราคาขาย
3unitsic_unit_usecodeic_codeหน่วยนับที่ใช้กับสินค้า
4warehousesic_wh_shelfcodeic_codeคลัง/ที่เก็บของสินค้า
5standard_costsic_standard_costcodeic_codeต้นทุนมาตรฐาน
6name_billingic_name_billingcodeic_codeชื่อสำหรับออกบิล
7name_marketic_name_merket ⚠️codeic_codeชื่อทางการตลาด (table สะกดผิดใน DB จริง)
8name_shortic_name_shortcodeic_codeชื่อย่อ
9name_posic_name_poscodeic_codeชื่อสำหรับขายหน้าร้าน (POS)
10color_useic_color_usecodeic_codeสีสินค้าที่ใช้
11size_useic_size_usecodeic_codeขนาดสินค้าที่ใช้
12pattern_useic_pattern_usecodeic_codeรูปแบบสินค้าที่ใช้
13manufacturersic_manufacturer_listcodeic_codeผู้ผลิตของสินค้า
14replacementsic_inventory_replacementcodeic_replace_codeสินค้าทดแทน — ic_replace_code คือสินค้าหลัก, ic_code คือสินค้าทดแทน
15bundlesic_inventory_bundlecodeic_code_bundleสินค้าพ่วง — ic_code_bundle คือสินค้าหลัก, ic_code คือสมาชิกใน bundle

POST Example

ส่งได้หลายสินค้าพร้อมกันใน items[] โดยแต่ละ item มี header เป็นบังคับ ส่วน sub-section อื่น ๆ ส่งเฉพาะที่ต้องการ

ตัวอย่างเต็ม (ครบทุก section)

json
{
  "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 }
      ]
    }
  ]
}

ตัวอย่างขั้นต่ำ (เฉพาะสินค้าใหม่ + บาร์โค้ดเดียว)

json
{
  "items": [
    {
      "header": {
        "code": "ITEM260609010",
        "name_1": "สินค้าเดี่ยว",
        "item_type": 0,
        "status": 0
      },
      "barcodes": [
        { "barcode": "8851234599999", "unit_code": "PCS", "price": 50 }
      ]
    }
  ]
}

Response Success

json
{
  "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

http
GET http://localhost:8086/SMLJavaRESTService/v5/api/documents/ic.inventory/ITEM260609001
json
{
  "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 / ข้อสำคัญ

เรื่องรายละเอียด
Requiredheader กับ 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
TransactionINSERT ทุก 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 ก่อน