Poseidonas

payload sales reports

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Computes what a Payload store sold, grouped by period, product and customer. It adds three read-only GET endpoints and exported server-side functions, with no collections, fields, hooks or admin components. It works with the official ecommerce plugin or any orders collection and requires Payload 3.88 or newer.

Features

  • Summary, by-product and by-customer endpoints guarded by a configurable admin check
  • Exported functions for reading reports in server-side code
  • Configurable order statuses that count as a sale, defaulting to processing and completed
  • Per-currency totals in minor units, never summed across currencies
  • Pages through orders with a maxOrders cap and a truncated flag
  • Optional registration of an admin view that you write yourself

Use cases

  • Build a custom admin dashboard from sales totals fetched from the endpoints
  • Run scheduled revenue summaries from a cron job using the exported functions
  • Check monthly order counts and units sold per product or customer

From the author

Sales totals by period, product and customer for Payload ecommerce, as data and endpoints with no admin component required.

Installation

npm i payload-sales-reports

1

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

30

Weekly Downloads

v1.0.2

npm Version

36.6 KB

Unpacked Size

0

Dependencies

GitHub stars

10 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20261
Dec 4, 20261
Dec 3, 20261
Dec 2, 20261
Dec 1, 20261
Nov 30, 20261
Nov 29, 20261
Nov 28, 20261
Nov 27, 20261
Nov 26, 20261
Nov 25, 20261
Nov 24, 20261
Nov 23, 20261
Nov 22, 20261
Nov 21, 20261
Nov 20, 20261
Nov 19, 20261
Nov 18, 20261
Nov 17, 20261
Nov 16, 20261
Nov 15, 20261
Nov 14, 20261
Nov 13, 20261
Nov 12, 20261
Nov 11, 20261
Nov 10, 20261
Nov 9, 20261
Nov 8, 20261
Nov 7, 20261
Nov 6, 20261
Nov 5, 20261
Nov 4, 20261
Nov 3, 20261
Nov 2, 20261
Nov 1, 20261
Oct 31, 20261
Oct 30, 20261
Oct 29, 20261
Oct 28, 20261
Oct 27, 20261
Oct 26, 20261
Oct 25, 20261
Oct 24, 20261
Oct 23, 20261
Oct 22, 20261
Oct 21, 20261
Oct 20, 20261
Oct 19, 20261
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20261
Oct 10, 20261
Oct 9, 20261
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20261
Oct 3, 20261
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20261
Sep 26, 20261
Sep 25, 20261
Sep 24, 20261
Sep 23, 20261
Sep 22, 20261
Sep 21, 20261
Sep 20, 20261
Sep 19, 20261
Sep 18, 20261
Sep 17, 20261
Sep 16, 20261
Sep 15, 20261
Sep 14, 20261
Sep 13, 20261
Sep 12, 20261
Sep 11, 20261
Sep 10, 20261
Sep 9, 20261
Sep 8, 20261
Sep 7, 20261
Sep 6, 20261
npm weekly downloads

24−5 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202624
Dec 4, 202625
Dec 3, 202628
Dec 2, 202633
Dec 1, 202633
Nov 30, 202634
Nov 29, 202620
Nov 28, 202629
Nov 27, 202636
Nov 26, 2026235
Nov 25, 2026229
Nov 24, 2026226
Nov 23, 2026225
Nov 22, 2026222
Nov 21, 2026213
Nov 20, 2026205
Nov 19, 20266
Nov 18, 202611
Nov 17, 202612
Nov 16, 202613
Nov 15, 202613
Nov 14, 202613
Nov 13, 202613
Nov 12, 202613
Nov 11, 20268
Nov 10, 20267
Nov 9, 20267
Nov 8, 202610
Nov 7, 202612
Nov 6, 202613
Nov 5, 202613
Nov 4, 202613
Nov 3, 202613
Nov 2, 202615
Nov 1, 202611
Oct 31, 20269
Oct 30, 20267
Oct 29, 20264
Oct 28, 20264
Oct 27, 20267
Oct 26, 20265
Oct 25, 20265
Oct 24, 20266
Oct 23, 20266
Oct 22, 202610
Oct 21, 202611
Oct 20, 20269
Oct 19, 20269
Oct 18, 20268
Oct 17, 20268
Oct 16, 20268
Oct 15, 20267
Oct 14, 20267
Oct 13, 20266
Oct 12, 20265
Oct 11, 20266
Oct 10, 20266
Oct 9, 20266
Oct 8, 20264
Oct 7, 20264
Oct 6, 20268
Oct 5, 20269
Oct 4, 202611
Oct 3, 202610
Oct 2, 202613
Oct 1, 202613
Sep 30, 202612
Sep 29, 202611
Sep 28, 202611
Sep 27, 202610
Sep 26, 202613
Sep 25, 202611
Sep 24, 202610
Sep 23, 202610
Sep 22, 20269
Sep 21, 20269
Sep 20, 202611
Sep 19, 20269
Sep 18, 202611
Sep 17, 202613
Sep 16, 202615
Sep 15, 202614
Sep 14, 202615
Sep 13, 202613
Sep 12, 202614
Sep 11, 202613
Sep 10, 202611
Sep 9, 202611
Sep 8, 202616
Sep 7, 202622
Sep 6, 202629

Each point is npm's rolling 7-day download count.

Health Score

72/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1340410409-root.svg)](https://payloaddirectory.dev/plugins/1340410409-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340410409-root"><img src="https://payloaddirectory.dev/badge/1340410409-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-sales-reports

npm node license payload

Totals what a Payload store actually sold, by period, by product and by customer, as functions and endpoints you can read from anywhere, with no admin component and no chart library.

  • Works with @payloadcms/plugin-ecommerce and with any collection that holds orders
  • No runtime dependencies, and no React anywhere in the package
  • Adds no collection, no field and no hook. Three read only endpoints, nothing else
  • Orders are read in pages; the whole order table is never held in memory

Read this before you install

This is the most fragile package of the family, and this is why. Every other package here stays on Payload's stable surface: collections, fields, hooks, endpoints. Reporting is the one job that tempts a package into the admin panel, and admin components are exactly where third party Payload packages die. Of 28 third party Payload packages surveyed on 19 August 2026, 14 had not been published since February 2026, and the ones that broke first were the ones that rendered inside the admin. Payload ships a stable release every 6.8 days; a component that reaches into the admin UI is a standing bet against that.

So this package ships no component at all. It is data and endpoints. If you want a view in the admin, you write the component in your own project, where it lives next to the Payload version you actually run, and you point this plugin at it with one config line. When Payload changes its admin API, your component breaks in your repository where you can fix it in an afternoon, instead of in a dependency that has been unmaintained for four months.

The second fragility is not code, it is arithmetic: what counts as a sale. That is stated exactly below rather than assumed.

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-sales-reports
import { salesReportsPlugin } from 'payload-sales-reports'

export default buildConfig({
  plugins: [
    salesReportsPlugin({
      timeZone: 'Europe/Athens',
    }),
  ],
})

Endpoint access defaults to a check for 'admin' in req.user.roles, and denies when there is no such field. If your users collection names it differently, say so:

salesReportsPlugin({
  isAdmin: ({ req }) => (req.user as null | { role?: string })?.role === 'admin',
})

As data, with no HTTP and no UI:

import { salesReport } from 'payload-sales-reports'

const report = await salesReport({ from: '2026-01-01', period: 'month', req })

Or GET /api/sales-reports/summary?period=month&from=2026-01-01:

{
  "byPeriod": [
    { "currency": "EUR", "orders": 41, "period": "2026-07", "revenue": 412300, "units": 63 },
    { "currency": "EUR", "orders": 55, "period": "2026-08", "revenue": 588150, "units": 91 }
  ],
  "currencies": ["EUR"],
  "orders": 96,
  "period": "month",
  "statuses": ["processing", "completed"],
  "timeZone": "Europe/Athens",
  "totals": [{ "currency": "EUR", "orders": 96, "revenue": 1000450, "units": 154 }],
  "truncated": false
}

What was measured

Which statuses count, and which do not

StatusCountedWhy
processingyesRead from @payloadcms/[email protected]: confirmOrder throws unless the payment intent reports succeeded, and only then writes the order. An order in processing is an order the customer paid for
completedyesThe same money, after the shop marked the order done
cancelledno
refundednoThe money went back

Change it with statuses: ['completed'] if your shop treats processing as unsettled. Every response repeats the list it used, so a figure can always be traced back to the rule that produced it.

This default is deliberately looser than the one in payload-downloads, which grants access only on completed. Handing over a file cannot be undone, so it waits for a deliberate act. A report is read only, so it counts the money that was actually taken.

Amounts are integers, in minor units

Read from fields/amountField.ts and currencies/index.ts: an amount is written as Math.round(value * 10 ** currency.decimals), and EUR, USD and GBP all declare decimals: 2. Every figure in every response is that same integer. Nothing here divides by 100, and nothing is stored as a float. Divide by 10 ** decimals at the point where you display it.

Currencies are never summed

Every row carries its own currency and totals is a list, one entry per currency. Two currencies in the same store produce two rows, never one wrong number. Pass currency=EUR to narrow it.

Why a logged in buyer and a guest buyer are grouped differently

Read from stripe/confirmOrder.ts, the order is written with

...(req.user ? { customer: req.user.id } : { customerEmail })

A logged in customer's order carries a customer and no customerEmail; a guest order carries the email and no customer. byCustomer keys on customer:<id> when there is one and email:<address> otherwise, and reports both fields on every row so you can see which kind of buyer a row is.

Why revenue per product is usually empty

Read from fields/cartItemsField.ts: an item gets an amount field only when the plugin is given currenciesConfig and individualPrices. createOrdersCollection calls it with neither. In a standard install an order line therefore carries product, variant and quantity, and no price at all.

So byProduct always reports units and orders, and reports revenue only when the lines carry an amount. When they do not, every revenue is null and the response says revenueByProductAvailable: false. Splitting the order total across its lines by quantity would produce a number that looks right and is wrong for any order with mixed prices, so it is not done.

Options

OptionDefaultMeaning
adminViewnone{ Component, path } for a view you wrote. Off by default; the package works fully without one
customersSlug'users'Slug of the customers collection
disabledfalseThe endpoints answer 404 and read nothing. Routes keep their shape
endpointPath'/sales-reports'Path below the Payload API route
isAdmin'admin' in req.user.rolesWho may call the endpoints
limit50Rows returned by byProduct and byCustomer. 0 returns all
maxOrders50000Orders one report reads before stopping and reporting truncated: true
ordersSlug'orders'Slug of the orders collection
pageSize500Orders read per query
period'month'Grouping used when a request does not ask for one
productsSlug'products'Slug of the products collection, read only to name a product
statuses['processing', 'completed']Order statuses that count as a sale
timeZone'UTC'IANA zone the period boundaries are cut on
variantsSlug'variants'Slug of the variants collection

A value that cannot be used is replaced by its default rather than being applied. A negative limit becomes 50, an unknown period becomes 'month', a time zone the platform does not recognise becomes 'UTC', and an empty statuses list becomes the default rather than counting nothing.

Query parameters accepted by all three endpoints: from, to, period, currency, limit.

What it adds to your database

Nothing. No collection, no field, no hook, no index. It only reads.

Three endpoints are added, all GET and all guarded by isAdmin:

EndpointReturns
/api/sales-reports/summarytotals, byPeriod, currencies, orders, statuses, timeZone, truncated
/api/sales-reports/by-productbyProduct, revenueByProductAvailable, orders, truncated
/api/sales-reports/by-customerbyCustomer, orders, truncated

Exported for server side use: salesReportsPlugin, salesReport, salesByPeriod, salesByProduct, salesByCustomer, ordersWhere, periodKey, isoWeek, partsIn, isPeriod, resolveConfig.

Building your own admin view

The plugin will register a view you wrote, and it imports nothing from React to do it:

salesReportsPlugin({
  adminView: {
    Component: '/components/SalesReports#SalesReports',
    path: '/sales-reports',
  },
})

The component is yours, in your own project, and it can fetch /api/sales-reports/summary like any other client. If Payload changes how custom views are registered, remove that one option and every endpoint and every exported function keeps working exactly as before. That is the whole point of the flag.

Honest limits

Reports are computed by paging, not by a database aggregate. Payload has no stable public API for a GROUP BY or a $group that works the same on the PostgreSQL and MongoDB adapters, and dropping to payload.db would tie this package to one of them. So orders are read pageSize at a time, accumulated into maps and released. Memory follows the number of distinct groups, not the number of orders; time follows the number of orders. The query count follows directly from the page size:

Orders in rangeQueries at the default page size of 500
5001
500010
50000100
more than 50000100, then it stops and reports truncated: true

For a store past that size, run the report from a cron into a stored summary rather than on request, and raise maxOrders deliberately.

A report is a request, and requests time out. Nothing here is cached. A summary over five years of a busy store is a long request; narrow it with from and to, or precompute.

Revenue per product is usually unavailable. See above. units is always right; revenue is null unless your order lines carry an amount.

The same human can appear twice in byCustomer. Someone who bought once as a guest and once signed in produces two rows, because the two orders share no field. There is no reliable join, and guessing one would silently merge two different people who share an address.

Periods are cut in one zone for the whole report. timeZone applies to every row. A store selling across zones gets one consistent cut, not a local one per order.

truncated: true means the figures are incomplete. It is never a rounding warning. Treat any truncated report as a sample.

Refunds are counted as absent, not as negative. A refunded order leaves the totals entirely; it is not subtracted from the period it was placed in. Partial refunds are invisible, because the official schema has no record of one. That belongs in payload-refunds.

Orders without a createdAt fall out of byPeriod. They stay in totals, byProduct and byCustomer, so the sum of the periods can be smaller than the total.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins