Skip to content

Sales Report

1. Overview

PropertyValue
IDFEAT-SALE-REPORT
StatusStable
Ownersale-team
Depends onSaleOrder, SaleOrderItem, PurchaseOrder (cross-package read for purchase summary)

SalesReportService exposes read-only aggregations over completed sale orders, intended for dashboards and end-of-day reports. All queries push down to repository SQL methods (no in-memory aggregation).

2. Operations

SalesReportService (sales-report.service.ts — 75 lines, thin wrapper over repos).

MethodRepository SQLReturns
getDailySummarySaleOrderRepository.getDailySummaryDaily totals: { date, orderCount, subtotal, tax, discount, total } per day
getProductSalesSaleOrderRepository.getProductSalesSales by product: { productVariantId, name, qty, total, ... }
getCategorySalesSaleOrderRepository.getCategorySalesSales by category: { categoryId, name, qty, total, ... }
getCategorySummarySaleOrderRepository.getCategorySummarySingle-category drill-down
getPurchaseSummaryPurchaseOrderRepository.getDailySummarySales-side view of purchase orders for cost-of-goods comparison

3. REST Endpoints

VerbPathAuthPermissionHandler
GET/reports/sales/summaryJWT/BASICSalesReport.dailySummarygetDailySummary
GET/reports/sales/by-productJWT/BASICSalesReport.byProductgetProductSales
GET/reports/sales/by-categoryJWT/BASICSalesReport.byCategorygetCategorySales
GET/reports/sales/category/:categoryIdJWT/BASICSalesReport.categorySummarygetCategorySummary
GET/reports/sales/purchase-summaryJWT/BASICSalesReport.purchaseSummarygetPurchaseSummary

Common query params (per endpoint, validated by zod):

ParamTypeDescription
fromISO dateStart of range
toISO dateEnd of range
merchantIdstringRequired for non-system roles (auto-filtered)
groupByenumday / week / month (where applicable)

Live OpenAPI: /v1/api/sale/doc/openapi.json.

4. Performance Notes

ConcernHandling
Long ranges (>90 days)Repository SQL uses indexed (merchantId, status, completedAt) to scan only COMPLETED orders
Concurrent dashboard readsNo caching today; repeated calls hit DB. Add Redis cache if pressure observed.
Cross-package PurchaseOrder accessRead via PurchaseOrderRepository which is from @nx/core — same DB, no HTTP roundtrip

5. Events

Outbound: none. Reports are pull-based via REST.

  • Domain ModelSaleOrder / SaleOrderItem schemas
  • API REST — live OpenAPI spec at /doc/openapi.json

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.