ภาพรวมของ Product API
เนื้อหานี้สำหรับการใช้งาน New Product API ผ่าน /product-masters
เท่านั้น
ประเภทของสินค้า
สินค้าในโปรแกรม FlowAccount สามารถแบ่งได้ออกเป็น 3 ประเภท ซึ่งใน OpenAPI ใช้ค่าของ type
ในการกำหนดหรือจำแนกสินค้าแต่ละประเภท ดังนี้
- สินค้าประเภทบริการ (Service)
type = 1
- สินค้าประเภทไม่นับสต็อก (Non Inventory)
type = 3
- สินค้าประเภทนับสต็อก (Inventory)
type = 5
มีทั้งแบบที่มีหน่วยหลักหน่วยเดียว (single-unit) และแบบหลายหน่วย (multiple-unit)
โครงสร้างของ Request และ Response Payload
การจัดการข้อมูลสินค้าผ่าน OpenAPI ทั้ง request และ response payload แบ่งข้อมูลออกเป็น 2 ระดับ ซึ่งมีโครงสร้างเป็น node และ element ดังนี้
-
Product หรือ Product Master เป็นระดับ node ที่แทนสินค้าชิ้นหนึ่ง ๆ ในระบบ FlowAccount ผู้ใช้งานสามารถจัดการข้อมูลสินค้าแต่ละชนิดได้ในระดับนี้
-
Product List เป็นระดับ element ที่เป็นตัวแทนหน่วยสินค้าหน่วยหนึ่ง ๆ ซึ่งถูกใช้อ้างอิงในเอกสารต่าง ๆ ของระบบ FlowAccount
- ข้อมูลในระดับนี้ประกอบด้วยรายละเอียด เช่น รหัสบาร์โค้ด, ราคาซื้อขาย และข้อมูลอื่น ๆ ที่เกี่ยวข้อง
- ข้อมูลเหล่านี้ใช้ในการประมว ลผล การซื้อขายในเอกสาร, การสต็อกสินค้า, และ การบริหารการเงินสำหรับเอกสารค่าใช้จ่าย
สำหรับสินค้าประเภทบริการ, ไม่นับสต็อก และสินค้านับสต็อกแบบหน่วยเดียว 1 Product (node) จะมีเพียง 1 Product List (element) เท่านั้น ส่วนสินค้านับสต็อกแบบหลายหน่วย 1 Product (node) จะมีอย่างน้อย 2 Product List (element) ได้แก่:
- สินค้าหลัก (Main Product) - หน่วยหลักของสินค้า
- สินค้าย่อย (Sub Product) - หน่วยสินค้าอื่นที่ใช้ในรายการซื้อขาย
ตัวอย่าง response payload ของสินค้า
- บริการ
- สินค้าไม่นับสต็อก
- สินค้านับสต็อกแบบหน่วยเดียว
- สินค้านับสต็อกแบบแยกหน่วย
{
"id": 28775004,
"type": 1,
"name": "bypass monitor",
"code": "FR-5rxgks",
"categoryId": null,
"categoryName": "",
"sellSettings": {
"vatType": 1,
"description": "Service Selling Description - Generic",
"chartOfAccountId": 207820783,
"chartOfAccountCode": "41210",
"chartOfAccountName": "รายได้จากการให้บริการ"
},
"buySettings": {
"vatType": 3,
"description": null,
"chartOfAccountId": null,
"chartOfAccountCode": null,
"chartOfAccountName": null
},
"nonInventorySettings": {
"productNonInventoryType": null
},
"inventorySettings": {
"inventoryPublishedOn": null,
"averageSellPrice": null,
"averageBuyPrice": null,
"remainingStock": null,
"totalValueInHand": null,
"warehouseId": null
},
"mainProductId": 51609899,
"mainUnitId": null,
"mainUnitName": "",
"productLists": [
{
"id": 51609899,
"unitId": null,
"unitName": "",
"isMainProduct": true,
"sellPrice": 93.57332000,
"sellPriceWithVat": 100.12346000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": null,
"convertRatio": 1.0,
"hasMovement": false
}
]
}
{
"id": 210827,
"type": 3,
"name": "เม็ดกาแฟไม่นับสต๊อก",
"code": "COFFEE-NONINV02",
"categoryId": 46273,
"categoryName": "วัตถุดิบ",
"sellSettings": {
"vatType": 1,
"description": "เมล็ดกาแฟชั้นดี",
"chartOfAccountId": 2625985,
"chartOfAccountCode": "41110",
"chartOfAccountName": "รายได้จากการขายสินค้า"
},
"buySettings": {
"vatType": 3,
"description": "ข้อมูลสำหรับการซื้อ จาก บริษัท แสนดีการคั่ว จำกัด",
"chartOfAccountId": 2626003,
"chartOfAccountCode": "51111.01",
"chartOfAccountName": "ซื้อสินค้า"
},
"nonInventorySettings": {
"productNonInventoryType": null
},
"inventorySettings": {
"inventoryPublishedOn": null,
"averageSellPrice": null,
"averageBuyPrice": null,
"remainingStock": null,
"totalValueInHand": null,
"warehouseId": null
},
"mainProductId": 279351,
"mainUnitId": 16606,
"mainUnitName": "กระสอบ",
"productLists": [
{
"id": 279351,
"unitId": 16606,
"unitName": "กระสอบ",
"isMainProduct": true,
"sellPrice": 934.57943900,
"sellPriceWithVat": 1000.00000000,
"buyPrice": 950.00000000,
"buyPriceWithVat": 1016.50000000,
"barcode": "COFFEE-BARCODE",
"convertRatio": 1.0,
"hasMovement": false
}
]
}
{
"id": 210831,
"type": 5,
"name": "เมล็ดโกโก้",
"code": "COCOA-INV",
"categoryId": 46273,
"categoryName": "วัตถุดิบ",
"sellSettings": {
"vatType": 3,
"description": "เมล็ดโก้โก้คุณภาพดีจากต้นโกโก้คัดคุณภาพ",
"chartOfAccountId": 2625985,
"chartOfAccountCode": "41110",
"chartOfAccountName": "รายได้จากการขายสินค้า"
},
"buySettings": {
"vatType": 3,
"description": null,
"chartOfAccountId": 2626003,
"chartOfAccountCode": "51111.01",
"chartOfAccountName": "ซื้อสินค้า"
},
"nonInventorySettings": {
"productNonInventoryType": null
},
"inventorySettings": {
"inventoryPublishedOn": "2024-01-01",
"averageSellPrice": 0.0,
"averageBuyPrice": 999.0,
"remainingStock": 10.0,
"totalValueInHand": 9990.0,
"warehouseId": null
},
"mainProductId": 279356,
"mainUnitId": 16606,
"mainUnitName": "กระสอบ",
"productLists": [
{
"id": 279356,
"unitId": 16606,
"unitName": "กระสอบ",
"isMainProduct": true,
"sellPrice": 100.00000000,
"sellPriceWithVat": 107.00000000,
"buyPrice": 1000.00000000,
"buyPriceWithVat": 1070.00000000,
"barcode": "COCOA-BARCODE",
"convertRatio": 1.0,
"hasMovement": true
}
]
}
{
"id": 210833,
"type": 5,
"name": "ขาหมูเยอรมันปรุงสำเร็จ - Fantastic",
"code": "KHAMOO-MU-02",
"categoryId": 46276,
"categoryName": "อาหารปรุงสำเร็จ",
"sellSettings": {
"vatType": 1,
"description": "ขาหมูบรรจุห่อ",
"chartOfAccountId": 2626151,
"chartOfAccountCode": "49060",
"chartOfAccountName": "รายได้จากการขายเศษวัสดุ"
},
"buySettings": {
"vatType": 3,
"description": "ขาหมูบรรจุแพ๊ค",
"chartOfAccountId": 2653072,
"chartOfAccountCode": "51211",
"chartOfAccountName": "ต้นทุนการให้บริการ ชั่วคราว"
},
"nonInventorySettings": {
"productNonInventoryType": null
},
"inventorySettings": {
"inventoryPublishedOn": "2024-01-01",
"averageSellPrice": 18.6916,
"averageBuyPrice": 95.0,
"remainingStock": 9900.0000,
"totalValueInHand": 940500.000000000,
"warehouseId": null
},
"mainProductId": 279359,
"mainUnitId": 21,
"mainUnitName": "กล่อง",
"productLists": [
{
"id": 279359,
"unitId": 21,
"unitName": "กล่อง",
"isMainProduct": true,
"sellPrice": 93.45794400,
"sellPriceWithVat": 100.00000000,
"buyPrice": 1000.00000000,
"buyPriceWithVat": 1070.00000000,
"barcode": "KHAMOO-MU-BOX",
"convertRatio": 1.0,
"hasMovement": true
},
{
"id": 279358,
"unitId": 16608,
"unitName": "ขีด",
"isMainProduct": false,
"sellPrice": 93.45794400,
"sellPriceWithVat": 100.00000000,
"buyPrice": 1000.00000000,
"buyPriceWithVat": 1070.00000000,
"barcode": "KHAMOO-MU-KEED",
"convertRatio": 5.00000000,
"hasMovement": true
},
{
"id": 279393,
"unitId": 16613,
"unitName": "pack",
"isMainProduct": false,
"sellPrice": 0.00000000,
"sellPriceWithVat": 0.00000000,
"buyPrice": 0.00000000,
"buyPriceWithVat": 0.00000000,
"barcode": "",
"convertRatio": 3.00000000,
"hasMovement": false
}
]
}
สินค้าหลัก, หน่วยหลัก และหน่วยย่อย
สินค้าหลัก (Main Product) คือรายการสินค้า (product list) ที่เป็นองค์ประกอบหลักของสินค้าในระบบ สอดคล้องกับโครงสร้างของ payload โดย
- สำหรับสินค้าประเภทบริการ, สินค้าไม่นับสต็อก และสินค้านับสต็อกแบบหน่วยเดียว สินค้านั้นจะถูกกำหนดให้เป็นสินค้าหลักโดยอัตโนมัติ
- สำหรับสินค้านับสต็อกแบบแยกหน่วย สินค้าหลักจะหมายถึงสินค้าที่กำหนดหน่วยหลักของสินค้านั้น ๆ
หน่วยสินค้าหลักหรือหน่วยหลัก (Main Unit) คือหน่วยที่ใช้แทนสินค้าในระบบ โดย:
- สำหรับสินค้านับสต็อกทั้งแบบหน่วยเดียวและแยกหน่วย หน่วยหลักนี้จะเทียบเท่ากับ Stock Keeping Unit
- ในรายการความเคลื่อนไหวของสินค้า ยอดคงเหลือจะแสดงผลในรูปแบบของหน่วยหลักเสมอ
หน่วยสินค้าย่อย (Sub Unit) คือหน่วยอื่น ๆ ที่ใช้สำหรับสินค้านับสต็อกแบบแยกหน่วย ซึ่ง:
- ใช้สำหรับการซื้อขายในหน่วยที่แตกต่างจากหน่วยหลัก
- ระบบจะยังสามารถติดตามความเคลื่อนไหวของสินค้าในหน่วยย่อยเหล่านี้ได้ โดยรายการที่ดำเนินการในหน่วยสินค้าย่อยจะถูกแปลงกลับเป็นหน่วยหลักเพื่อการบันทึกข้อมูลที่ เป็นมาตรฐาน
ใน response payload จะมี fields ที่เกี่ยวข้องได้แก่
mainProductId
เป็น product list id ของสินค้าหลัก เป็นค่าเดียวกับproductLists[*].id
ที่มีisMainProduct
เป็นtrue
mainUnitId
เป็น id ของหน่วยสินค้าหลัก มีค่า null สำหรับสินค้าที่ไม่ได้ระบุหน่วยmainUnitName
เป็นชื่อของหน่วยสินค้าหลัก มีค่าเป็น empty string สำหรับสินค้าที่ไม่ได้ระบุหน่วย
- หากต้องการระบุสินค้าด้วย Id ในรายการสินค้าของเอกสารและใช้ที่สินค้าหลัก สามารถใช้ค่า
mainProductId
ในitems[*].id
ได้ - สำหรับ Product API เดิมที่เ รียกผ่าน
/products
รายการที่มีค่าid
เท่ากับmainProductId
ถือว่าสินค้าดังกล่าวเป็นสินค้าหลัก