Developer Docs

เริ่มต้น

Partner API — Auth

Partner API — Products

Partner API — Inventory

Partner API — Customers

Partner API — Reports

Sales Summary

ดึงรายงานยอดขายสรุปของสาขาหนึ่ง ในช่วงเวลาที่กำหนด

Endpoint นี้คืนข้อมูลสรุป (Aggregate) เพียง response เดียว ไม่ใช้ Pagination — เหมาะสำหรับ Dashboard และ Reporting โดยตรง ไม่ต้องนำข้อมูลดิบมาคำนวณเอง

Endpoint นี้เหมาะสำหรับ:

  • แสดง KPI ยอดขายรายวัน / รายสัปดาห์ / รายเดือน บน Dashboard
  • เปรียบเทียบยอดขายระหว่างช่วงเวลา
  • Export รายงานสรุปสำหรับฝ่ายบัญชีหรือผู้บริหาร

Required Scope

read:reports

Access Token ต้องได้รับ Scope read:reports มิฉะนั้นระบบจะปฏิเสธคำขอ


Endpoint

GET /api/partner/v1/reports/sales-summary

Request Headers

Authorization: Bearer <access_token>

Query Parameters

ParameterTypeRequiredDescription
branch_idstring (UUID)Yesสาขาที่ต้องการดึงรายงาน ต้องอยู่ใน Token's allowed_branch_ids
fromstring (YYYY-MM-DD)Noวันเริ่มต้นของช่วงรายงาน (inclusive)
tostring (YYYY-MM-DD)Noวันสิ้นสุดของช่วงรายงาน (inclusive)

หมายเหตุ Date Range

หากไม่ส่ง from และ to ระบบจะคืน All-time Summary ของสาขานั้น (from และ to ใน response จะเป็น null)


Example Request

curl -X GET \
  "https://<host>/api/partner/v1/reports/sales-summary?branch_id=b1f85720-71cf-420e-a584-e36b75d3fd20&from=2026-06-01&to=2026-06-15" \
  -H "Authorization: Bearer <access_token>"

Example Response

{
  "data": {
    "branch_id": "b1f85720-71cf-420e-a584-e36b75d3fd20",
    "from": "2026-06-01",
    "to": "2026-06-15",
    "total_orders": 53,
    "total_revenue": "12510.4",
    "total_subtotal": "12510.4",
    "total_discount": "113.6",
    "total_tax": "818.4",
    "total_service_charge": "0",
    "total_refunded": "0",
    "average_order_value": "236.0452830188679245"
  }
}

SalesSummary Object

FieldTypeDescription
branch_idstring (UUID)สาขาที่รายงาน
fromstring | nullวันเริ่มต้นที่ใช้ในการคำนวณ (null หากไม่ส่ง parameter)
tostring | nullวันสิ้นสุดที่ใช้ในการคำนวณ (null หากไม่ส่ง parameter)
total_ordersnumberจำนวน Order ทั้งหมด — นับเฉพาะสถานะ COMPLETED และ PARTIAL_REFUNDED
total_revenuestring (decimal)ยอดขายรวม (sum of total_amount)
total_subtotalstring (decimal)ยอดรวมก่อนภาษีและค่าบริการ
total_discountstring (decimal)ส่วนลดรวมทั้งหมด
total_taxstring (decimal)ภาษีรวมทั้งหมด
total_service_chargestring (decimal)ค่าบริการรวมทั้งหมด
total_refundedstring (decimal)ยอดคืนเงินรวม
average_order_valuestring (decimal)ยอดเฉลี่ยต่อ Order = total_revenue / total_orders

Error Responses

Missing or Invalid branch_id

400 Bad Request
{
  "error": "invalid_request",
  "message": "branch_id is required"
}

Branch Not Found

404 Not Found
{
  "error": "not_found",
  "message": "Branch not found"
}

สาเหตุ:

  • branch_id ไม่ถูกต้อง
  • Branch อยู่นอกขอบเขตสิทธิ์ของ Token (allowed_branch_ids)