Skip to content

v5 Transaction: Sale Invoice

Dynamic Document API สำหรับใบขายสินค้า/บริการ

Module

sale.invoice

EndPoint

http
POST /SMLJavaRESTService/v5/api/documents/sale.invoice
GET  /SMLJavaRESTService/v5/api/documents/sale.invoice/{doc_no}

Table Mapping

SectionTableTypeLink
headeric_transobjectkey: doc_no
detailsic_trans_detailarraydetails.doc_no = header.doc_no
shipmentic_trans_shipmentobjectshipment.doc_no = header.doc_no
paymentcb_transobjectpayment.doc_no = header.doc_no, payment.trans_flag = header.trans_flag
payment.detailcb_trans_detailarraypayment.detail.doc_no = payment.doc_no, payment.detail.trans_flag = payment.trans_flag
ap_ar_trans_detailap_ar_trans_detailarrayap_ar_trans_detail.doc_no = header.doc_no, ap_ar_trans_detail.doc_date = header.doc_date

Defaults

FieldValue
header.trans_flag44
header.trans_type2
header.is_pos0
details.trans_flag44
details.trans_type2
shipment.trans_flag44

POST Example

POST accepts both direct payload and GET-style payload:

  • direct: { "items": [...] }
  • GET-style: { "data": { "items": [...] } }

When reusing GET output for POST, change document keys such as header.doc_no and related reference numbers. roworder is ignored on write.

json
{
  "items": [
    {
      "header": {
        "doc_no": "SI260609001",
        "doc_date": "2026-06-09",
        "cust_code": "AR260609001",
        "vat_type": 1,
        "vat_rate": 7,
        "total_value": 1000,
        "total_before_vat": 1000,
        "total_vat_value": 70,
        "total_amount": 1070
      },
      "details": [
        {
          "line_number": 1,
          "item_code": "ITEM001",
          "item_name": "สินค้า A",
          "unit_code": "PCS",
          "qty": 2,
          "price": 500,
          "sum_amount": 1000,
          "wh_code": "WH01",
          "shelf_code": "S01"
        }
      ],
      "shipment": {
        "transport_code": "KERRY",
        "transport_name": "Kerry Express",
        "transport_address": "Bangkok"
      },
      "payment": {
        "doc_no": "PAY260609001",
        "doc_date": "2026-06-09",
        "total_amount_pay": 1070,
        "cash_amount": 1070,
        "detail": [
          {
            "line_number": 1,
            "amount": 1070,
            "sum_amount": 1070
          }
        ]
      },
      "ap_ar_trans_detail": [
        {
          "doc_no": "SI260609001",
          "doc_date": "2026-06-09",
          "trans_flag": 44,
          "trans_type": 2,
          "bill_type": 34,
          "billing_no": "SO260609001",
          "billing_date": "2026-06-09",
          "ref_doc_no": "",
          "line_number": 1
        }
      ]
    },
    {
      "header": {
        "doc_no": "SI260609002",
        "doc_date": "2026-06-09",
        "cust_code": "AR260609002",
        "vat_type": 1,
        "vat_rate": 7,
        "total_value": 2000,
        "total_before_vat": 2000,
        "total_vat_value": 140,
        "total_amount": 2140
      },
      "details": [
        {
          "line_number": 1,
          "item_code": "ITEM002",
          "item_name": "สินค้า B",
          "unit_code": "PCS",
          "qty": 4,
          "price": 500,
          "sum_amount": 2000,
          "wh_code": "WH01",
          "shelf_code": "S01"
        }
      ],
      "shipment": {
        "transport_code": "FLASH",
        "transport_name": "Flash Express",
        "transport_address": "Chiang Mai"
      },
      "payment": {
        "doc_no": "PAY260609002",
        "doc_date": "2026-06-09",
        "total_amount_pay": 2140,
        "tranfer_amount": 2140,
        "detail": [
          {
            "line_number": 1,
            "amount": 2140,
            "sum_amount": 2140,
            "bank_code": "KBANK"
          }
        ]
      },
      "ap_ar_trans_detail": [
        {
          "doc_no": "SI260609002",
          "doc_date": "2026-06-09",
          "trans_flag": 44,
          "trans_type": 2,
          "bill_type": 34,
          "billing_no": "SO260609002",
          "billing_date": "2026-06-09",
          "ref_doc_no": "",
          "line_number": 1
        }
      ]
    }
  ]
}

GET Example

http
GET http://localhost:8086/SMLJavaRESTService/v5/api/documents/sale.invoice/SI260609001
json
{
  "success": true,
  "data": {
    "items": [
      {
        "header": {
          "doc_no": "SI260609001",
          "doc_date": "2026-06-09",
          "cust_code": "AR260609001",
          "vat_type": 1,
          "vat_rate": 7,
          "total_value": 1000,
          "total_before_vat": 1000,
          "total_vat_value": 70,
          "total_amount": 1070,
          "trans_flag": 44,
          "trans_type": 2,
          "is_pos": 0
        },
        "details": [
          {
            "doc_no": "SI260609001",
            "doc_date": "2026-06-09",
            "trans_flag": 44,
            "trans_type": 2,
            "line_number": 1,
            "item_code": "ITEM001",
            "item_name": "สินค้า A",
            "unit_code": "PCS",
            "qty": 2,
            "price": 500,
            "sum_amount": 1000,
            "wh_code": "WH01",
            "shelf_code": "S01"
          }
        ],
        "shipment": {
          "doc_no": "SI260609001",
          "doc_date": "2026-06-09",
          "trans_flag": 44,
          "cust_code": "AR260609001",
          "transport_code": "KERRY",
          "transport_name": "Kerry Express",
          "transport_address": "Bangkok"
        },
        "payment": {
          "doc_no": "SI260609001",
          "doc_date": "2026-06-09",
          "trans_flag": 44,
          "doc_ref": "",
          "total_amount_pay": 1070,
          "cash_amount": 1070,
          "detail": [
            {
              "doc_no": "SI260609001",
              "doc_date": "2026-06-09",
              "trans_flag": 44,
              "line_number": 1,
              "amount": 1070,
              "sum_amount": 1070
            }
          ]
        },
        "ap_ar_trans_detail": [
          {
            "trans_type": 2,
            "trans_flag": 44,
            "doc_no": "SI260609001",
            "doc_date": "2026-06-09",
            "billing_no": "SO260609001",
            "billing_date": "2026-06-09",
            "bill_type": 34,
            "ref_doc_no": "",
            "line_number": 1,
            "last_status": 0
          }
        ]
      }
    ]
  }
}

Rules

  • trans_flag, trans_type ถูกกำหนดจาก manifest ไม่ควรให้ client คุมเอง
  • ถ้าไม่ส่ง details[].doc_no, details[].doc_date, details[].trans_flag ระบบจะเติมจาก header/default
  • ถ้าไม่ส่ง payment.doc_no และ payment.trans_flag ระบบจะเติมจาก header.doc_no และ header.trans_flag
  • field ที่ไม่มีใน table ที่เกี่ยวข้องจะ error FIELD_NOT_FOUND