Sales Reports

Sales reporting plugin that totals revenue, units and orders by period, product and customer from Payload order collections.

Community 0 MIT v1.0.0

Installation

pnpm add payload-sales-reports

About

The plugin reads an orders collection (the one shipped by `@payloadcms/plugin-ecommerce` or any equivalent) and produces sales totals grouped by period, product and customer. It exposes the data as plain async functions and as three read-only `GET` endpoints under the Payload API route: `/sales-reports/summary`, `/sales-reports/by-product`, and `/sales-reports/by-customer`. It adds no collection, no field, and no hook, so the database schema is untouched and everything is computed by paging through orders at query time. Configuration is small. `timeZone` sets the IANA zone used to cut period boundaries. `isAdmin` gates every endpoint and defaults to checking `'admin'` in `req.user.roles`, but accepts a function so a differently shaped users collection can be used. `statuses` controls which order statuses count as a sale and defaults to `['processing', 'completed']`. `limit` caps the rows returned by `byProduct` and `byCustomer`, `pageSize` controls how many orders are read per query, and `maxOrders` bounds how many orders a single report will read before stopping and reporting `truncated: true`. Orders are read in pages; the whole order table is never held in memory. Amounts are returned as integers in minor units, matching how the ecommerce plugin writes them (`Math.round(value * 10 ** currency.decimals)`). The plugin never sums across currencies: every row carries its own `currency`, `totals` is a list with one entry per currency, and `currency=EUR` narrows a response. Per-product revenue is reported only when order lines carry an amount field, which a standard `createOrdersCollection` install does not set, so `byProduct` always returns `units` and `orders` and reports `revenueByProductAvailable: false` unless line amounts exist. The package ships no React component. An admin view is optional: pass `{ Component, path }` via `adminView` to register a view you write in your own project, where it stays next to the Payload version you run. The plugin only reads data; it performs no writes. Invalid option values fall back to defaults instead of being applied.

Package info

Package name
payload-sales-reports
Latest version
1.0.0
Unpacked size
35 kB
License
MIT
Last publish
Aug 20, 2026

More from Poseidonas

View profile